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 expression:
1, 00, 13 and up.
/^(0[1-9]|1[0-2])$/
/^01|02|03|04|05|06|07|08|09|10|11|12$/
我认为这是一个更好的,它接受'05',但也接受'5'作为一个月:
/(^0?[1-9]$)|(^1[0-2]$)/
这会奏效
/(0[1-9])|(1[012])/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.