Reputation: 3153
What is the javascript regular expression for 24H time? Such as:
18:30
I need to assign the regex string to a variable to be used over and over.
Thank you
Upvotes: 0
Views: 150
Reputation: 31131
You can use
^([01]\d|2[0-3]):?([0-5]\d)$
It will require either a 0 or 1, followed by any digit (00 to 10 hours) or a 2 followed by 0, 1, 2, 3 (20 to 23 hours), an optional colon (take out the ?
to make it required) and then a 0-5 followed by any digit (minutes).
Upvotes: 0