473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Time validation with CustomValidator

Hey everyone,

I've been working with the AJAX Control Toolkit (Version 1.0.20229) to make a web form. I used the masked textbox to create two textbox for Time input (HH:MM format). It's supposed to be a range - the Start time textbox value should be smaller than the End time textbos.

I'm looking for the best way to validate the correct order of the times. I've been trying several approaches - and I'm kind of stuck.

Any ideas on best practice?
Apr 7 '08 #1
7 3177
mrhoo
428 256MB
1. Make the smaller date the start date, the larger date the end date, however they were delivered.

2. Or use the start date input to display a menu of selectable dates for the second choice.
Apr 7 '08 #2
Thank you mrhoo for the reply,

but i'm having trouble with your suggestions - perhaps i should have explained my User Interface better.

I have two textboxes, both need to get Time input. The way I want it to look is as if I have a validator for each control, checking every time I leave the focus of either checkbox if the time range is valid. I wrote the validation function in JavaScript, I just don't know how exactly I should use it

(for instance, should I implement two custom validators, or should i work with a CompareValidator? Should I somehow access a validator to display/hide it through JavaScript?

To your suggestions -
1. Make the smaller date the start date, the larger date the end date, however they were delivered.
The user interface is pretty strict - i have a section with the earlier date control, earlier time control (the one relevant to my question), etc. and likewise for the later date / time and other data. I won't be able to move the value between the textboxes and ignore the way the input looked on the screen originally.

2. Or use the start date input to display a menu of selectable dates for the second choice.
I need the validation for Time, and i need the user to be able to enter any time in both textboxes - just as long as once focus is lost the validation method runs and displays the message if necessary.

any more suggestions please?

Thanks,
Frankie
Apr 7 '08 #3
acoder
16,027 Expert Mod 8TB
This is not too difficult using simple JavaScript, rather than using a CustomValidator (which I assume is something .NET).

Just split the hour and minute values from the time value using the split() method, then compare the two hours and minutes, e.g.
Expand|Select|Wrap|Line Numbers
  1. // time1/2 are textboxes and assume correct format
  2. var hm = time1.value.split(":");
  3. var hm2 = time2.value.split(":");
  4. var hours = parseInt(hm[0]);
  5. var mins = parseInt(hm[1]);
  6. // ...for hm2 too...
  7. if (hours2 > hours) {// validation fails here...
  8. ...
  9. } else if ((hours2 == hours) && (mins2 > mins)) {// fails validation 
  10. ...
  11. } else return true;
Apr 9 '08 #4
This is not too difficult using simple JavaScript, rather than using a CustomValidator (which I assume is something .NET).

....
Thanks acoder - I know how to code the JavaScript logic to check if the hours are valid/invalid.

What I'm having trouble with is the .NET part - or specifically, how to make it look like a validator behavior, without messing with the other validators.

It IS something .Net so you'd have to know what validators are / how they work, to help - since that's my main issue.
Apr 12 '08 #5
acoder
16,027 Expert Mod 8TB
In that case, I suggest you ask in the .NET forum where someone more experienced with .NET controls should be able to help you better.
Apr 12 '08 #6
In that case, I suggest you ask in the .NET forum where someone more experienced with .NET controls should be able to help you better.
Ok, I'll repost - thanks
Apr 12 '08 #7
kho786
1
Hi everyone I have a validator control for move in dates.
I cannot figure out why a date in 2009 returns an error move in date invalid.

I am using javascript. page in question: Houston Apartment Locators | Apartments in Houston | Houston Texas Apartments
Dec 9 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ananda Sim | last post by:
Hi All, I'm having problems setting up a validation mechanism that covers three optional <asp:textbox> - Only one of these need to be filled - any one. The standard RequiredFieldValidator will...
3
by: simon | last post by:
I have 2 <asp:textbox controls>: <asp:textbox id="txt1" Runat="server" ></asp:textbox> <asp:textbox id="txt2" Runat="server" ></asp:textbox> User must insert the value either in txt1 OR in...
1
by: Dan Sikorsky | last post by:
I'm getting the following message when I try to add a CustomValidator control to the ValidationSummary to display an error message at runtime, and displaying ex.message in AddValidationControl...
1
by: Liz | last post by:
I have a page with several dropdownlists, several text boxes and several buttons which perform calculations. I need to validate one dropdownlist (not the whole page) with the click of one button. I...
7
by: ujjc001 | last post by:
Hello, it a .net app, in my client javascript code I would like to find out what event caused the page to validate. No, setting a hidden this or that will not do. I just want to know what event...
12
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
4
by: kpg | last post by:
I can't get the CustomValidator (CV) ErrorMessage to display in the ValidationSummary. On the same page I have several RequiredField Validators and a Range Validator, that all work just fine,...
1
by: Fendi Baba | last post by:
I wrote a simple validation routine. I am trying to trigger validation on group of fields if an option on another radio button is selected. Sub ValidateAdd_ServerValidate(ByVal objSource As...
3
by: hardieca | last post by:
Hi, I've created an n-tier app where validation rules reside in the business layer. When a webform is saved, a business object examines its state, and if some property is invalid, throws a...
5
by: =?Utf-8?B?R2FyeSBMYXJpbWVy?= | last post by:
Created a Custom Validation Ctrl in EW2 to validate a text box entry. Want to make sure entry is evenly divisible by 7, and that value is not 0. However, args.IsValid = false, even if 77 is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.