Can anyone tell me how to validate time (which is an html input element) in the format as hh:mm:ss AM/PM in javascript
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are probably better regexes out there but lets do something basic.
Get the input and attach an event on blur (will not explain how to do this; search for ‘attach event to dom element in javascript’ or something alike)
In that even you can do something like this:
For better regexes to test time formats, or other formats, search for ‘validate time regex javascript’ or something similar (there are tons out there).
This particular regex validates time, you can play arround with it here if you want:
http://rubular.com/r/cYs1n3UuKO
Bear in mind that ruby and javascript regexes do differ slightly, but for something as simple as this you can use rubular which has a good interface for easy testing.