|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Time Validation
Hi, I'm not too savvy with Javascript, and I need to be able to Validate a text box to make sure the user has input a valid time. I have seached quit a bit, and I have not found much information on how to do this.Times accepted are military, HH:MM:SS AM/PM, HH:MM AM/PM, but I can restrict it to any of these if i need to. Any Help would be appreciated. Thanks |
|
#2
|
|||
|
|||
|
You have a couple choices to make. Since it looks like you have opted to put it all in on text box (???), you can either parse the pieces using the javascript string functions or you can use a regular expression to validate: http://www.devguru.com/Technologies...ref/regexp.html
Since you seem to be allowing two different options of entering the text , you will probably want to go with a regular expression.Now, if I were doing this, I'd break it up into its respective parts as dropdowns. [hh] [mm] [ss] [ampm] If you decided to leave off the [ampm] drop down then obviously your [hh] dropdown would need to go from 0 - 23, but if you keep the [ampm] you will have a twelve hour [hh] dropdown. If you want to get really slick, just create both versions in a table or between <div></div> and have a radio or checkbox for the user to select which method they want to enter their time in (military or 12hour). When the box is selected use dynamic html to show one or the other. You can easily disable the other elements so that they do not form post/get.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
Yeah, if I had developed this backend on my own, I would've used drop-downs. In this case it is an already developed backend, and I have the task of adding CS Validations to these forms. If I wanted to use dropdowns, I'd have to develop a server-side script to examine an existing field value from a Record in a database, and create script to have the dropdowns select the existing time values.
I think I'll pass on making it slick. Thanks for the info. |
|
#4
|
|||
|
|||
|
Answer for your question
Confused:
Your answer is the following ^[0-9]+:[0-9]+ [aApP]+[mM]+$ Good day.. Anthony Antony Times accepted are military, HH:MM:SS AM/PM, HH:MM AM/PM, but I can restrict it to any of these if i need to. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Time Validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|