I want to make a regular expression that direct the time format is valid, the format should like this:
HH:MM
so, I create a regular expression like this:
/\b[0-2][0-9]\:[0-5][0-9]\b/
But the problems occur, the user still can input something like 29:59. Which is not a valid time. How can I solve it? Thank you.
Use a regex
ORfor the hour:The
([01][0-9]|2[0-3])part is saying hours can be anything 00-19 or 2 with (0-3).A regex
ORtakes the form of(A|B)