I want regular expression for HH:MM:SS AM/PM here HH must be 1-12 only, MM must 60 min, SS as usual (60 sec.) I 开发者_开发技巧any have it properly ...?
(0[1-9]|1[0-2]):([0-5][0-9]:[0-5][0-9]|(59|44|29):60) (AM|am|PM|pm)
/^([1-9]|10|11|12):[0-5][0-9]:[0-5][0-9] [AP]M$/
If you want to be able to have the zero padding as optional as well as leap seconds:
/^((0?[1-9])|(1[0-2])):[0-5]\d:(([0-5]\d)|(60)) [AP]M$/
The breakdown:
(0?[1-9]|1[0-2])
1-9 (with optional leading zero) or 10-12
[0-5][0-9]
00-59 (0-5 for first digit, 0-9 for second)
([0-5][0-9])|(60)
Leap seconds
[AP]M
AM/PM
精彩评论