Regular expression to check month

What is a regular expression for checking a month with a leading zero?

Skip regex:

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

The regex does not work:

1, 00, 13 and up.
+3
source share
4 answers
/^(0[1-9]|1[0-2])$/
+16
source
/^01|02|03|04|05|06|07|08|09|10|11|12$/
+2
source

I think this is better, it accepts "05", but also "5" per month:

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

it will work

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

Source: https://habr.com/ru/post/1746477/


All Articles