I have an input field in which the user enters time in the format mm: hh. The format is specified inside the field (the default value is 09:00), but I still want to perform a client-side check to make sure the format is correct.
Since the existing client-side validation is in jQuery, I would also like to keep this in jQuery.
I am basically a PHP programmer, so I need help writing this in optimal mode.
I know that I can check every single character (first two = digits, third = ':', last two = digits), but is there any way to do this more elegantly, while checking the number of hours does not exceed 23 and the number of minutes does not exceeds 59?
In PHP, I would use regular expressions, I assume something similar for jQuery?
Something like this makes sense to me:
([01]?[0-9]|2[0-3]):[0-5][0-9]
But I'm not too familiar with jQuery syntax, so I'm not sure what to do with it.
jovan source
share