On a 12-hour clock, if the first digit is 0, the second digit allows all 10 digits, but if the first digit is 1, the second digit must be 0, 1, or 2. In a regular expression, we write this as ‹ 1[0-2]|0?[1-9] ›.
I am not very good with regex. I have the following time: 12:00am
.
I need a Javascript regex that respect this format: hh:mm[am/pm]
var regex = /^(\d\d):(\d\d)\s?(?:AM|PM)?$/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With