Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing a user to enter correct time (hours/minutes)

Status
Not open for further replies.

KingElvis

Programmer
Jan 28, 2004
39
0
0
IL
Is there a way to ensure (and verify) that a viewer inputs the correct time - hours and minutes - WITHOUT having to put drop-down boxes on my page.

I could place two drop-down boxes on the page (one for the hours and one for the minutes), but ideally, I would like to see just an Input Box with the following contents:

hh:mm

The user will input the hours and minutes, and the data will be verified.
 
You could code the verification yourself. All you would need to really do is to split whatever is entered on the : then verify that the first part is between 0 and 23 and that the second part is between 0 and 59.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
OK

Why not input box max lenght 6
Validate using instr() to ensure that character 3=:
then evaulate left(2) <24
evaluate right(2) <60

or is this to simple?

 
this might be even more straightforward using Regular Expressions. There are plently of example of using these in the forum and the FAQs

Tony
________________________________________________________________________________
 
I think my prefernce would be to put both a client-side and server-side check on the input box. Do the client-side one in either the form's onSubmit event or the inputs onClur event. That way you can correct the user befoe they leave the page but also protect yourself from someone spoofing the form.

A regex would probably be easiest, something along the lines of ([0-1]?\d)|(2[0-3]):[0-5]?\d

That should cover all the hours and minutes with or without zero-filling, should work for both checks.

-T

barcode_1.gif
 
Tarwn,

Thanks for the advice, but could you elaborate a bit more. Give some more code so that I can understand. I am a beginner! Thanks
 
I'll do you one better, here s a link to an ASP regExp tutorial over at 4guys:
And here is a similar tutorial from the javascript angle:

Reguklar expressions can be a real painin the begunning and I avoided them for quite a while, but after you get into them you'll realize just how really useful (and cool!) they can be. Of course you also realize how absolutely painfulthey can be sometimes, also, but we won't mention that ;)

-T

barcode_1.gif
 
You could just have a button that the user clicks and have the button enter the exact time by using the date method

Just an idea, but there wouldn't be any entering of information from the user
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top