After google searching, searching this site as well as jQuery found there was no easy way to validate time value.
By the looks of things it suggest using addMethod and use the to regexpess the value to check against what time should look like.
However decided to look at the jquery.validate.js and how dateISO was checked, it looked lot easier way to do it, so I then copied all data relating to dateISO and called it timeISO and changed the string to validate time and used the following time sting
^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$
Is there some reason why one should not modify jquery.validate.js and do it the way I have? Just a little bit worried as all my searching on google and this forum it was never suggested.
You can add custom methods to
jQuery.validate. There’s probably one available for this but I coded this 24h time format validation as an example:Fiddle
Documentation.
You can also sum it up in a single regular expression (source):
And if you’re using HTML5, you can use the
patternattribute:Fiddle
Keep using the
jQuery.validatemethod if you need compatibility with older browsers though:Demo