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])/
精彩评论