Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 expression:

1, 00, 13 and up.
like image 770
Michael Kniskern Avatar asked Nov 29 '22 18:11

Michael Kniskern


2 Answers

/^(0[1-9]|1[0-2])$/
like image 99
Seb Avatar answered Dec 02 '22 06:12

Seb


/^01|02|03|04|05|06|07|08|09|10|11|12$/
like image 37
Daniel Trebbien Avatar answered Dec 02 '22 06:12

Daniel Trebbien