You can use something simpler:
^(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])([12]\d{3})$
He fixes the day, month, year and checks everything, except that February 29 is actually a leap year. (To do this, I just did the math a captured year / date later, rather than trying to write it into an expression).
Working example: http://regex101.com/r/dH8mG3
Explanations:
- Capture the day: 01-29
- OR 31, if not succeeded by 02, 04, 06, 09, or 11
- OR 30, if not succeeded by 02
- Capture the month: 01-12
- Capture the year: 1000-2999 (you could narrow this down
by using number ranges like
(1[8-9]\d{2}|20\d{2}) == 1800-2099
source
share