By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 3,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

javascript code for validating the time accepted in the form of string

P: 7
Accepting the String in normal text box and checking weather the srting is Date or not in javascrit
Oct 26 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Please provide more details include your code. What would be considered a valid date/time?
Oct 26 '08 #2

P: 7
Please provide more details include your code. What would be considered a valid date/time?
i need the code for checking weather the enterd string by user is valid time or not in very short code......
Nov 2 '08 #3

acoder
Expert Mod 15k+
P: 16,027
I understood that much, but that's not enough. What would be considered valid, e.g. 12 hour format, 24 hour, just numbers and ":" or "AM/PM" too and so on.

You can use a regular expression to validate the field, but post your code. What have you managed so far?
Nov 2 '08 #4

P: 7
i need the code for checking weather the enterd string by user is valid time or not in very short code......
i have no code.but had a query saying that write the code for checking wheather the given string in time or not
Nov 12 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Since you refuse to provide more details, I'll just give you a general idea.

Match the format first using a regular expression, e.g.
Expand|Select|Wrap|Line Numbers
  1. /^\d{1,2}\:\d{2}\:\d{2}(\s?(AM|PM))?$/i
then check each part individually for correctness, e.g. that hours is between 0 and 12, that minutes are between 00 and 59 and so on.
Nov 13 '08 #6

Post your reply

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