开发者

Regular expression for a formatted time

开发者 https://www.devze.com 2023-04-07 06:22 出处:网络
I have a time format that I want to check if it is correct. The format should be [H]H.MM[a|p]. Hours should be fro开发者_StackOverflowm 1 to 12, minutes as usual and the ending character either an a o

I have a time format that I want to check if it is correct. The format should be [H]H.MM[a|p]. Hours should be fro开发者_StackOverflowm 1 to 12, minutes as usual and the ending character either an a or p. There should also be a dot between the hours and minutes.

I tried with this reg ex, but it didn't work:

var reg = /^([1-9|10|11|12])\.[0-5][0-9][pa]$/;


You meant

var reg = /^([1-9]|10|11|12)\.[0-5][0-9][pa]$/;


Try that:

^([1-9]|10|11|12)\.[0-5][0-9][ap]$
0

精彩评论

暂无评论...
验证码 换一张
取 消