开发者

Regular expression for validating month

What is the regular expression for validating a month with the leading zero?

Passes regular expression:

01,02,03,04,05,06,07,08,09,10,11,12

Fails regular expre开发者_JAVA技巧ssion:

1, 00, 13 and up.


/^(0[1-9]|1[0-2])$/


/^01|02|03|04|05|06|07|08|09|10|11|12$/


I think this is a better one, it accepts '05', but also '5' as a month:

/(^0?[1-9]$)|(^1[0-2]$)/


this will work

/(0[1-9])|(1[012])/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜