Regular Expressions 101

Community Patterns

YYYYMMDD w/Leap Year Check

0

Regular Expression
PCRE (PHP <7.3)

/
^(([0-9][0-9][0-9][0-9])((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01])|(0[469]|11)(0[1-9]|[12][0-9]|30)|(02)(0[1-9]|1[0-9]|2[0-8]))|([0-9][0-9])([02468][048]|[13579][26])(02)(29))$
/
gm

Description

Validate dates in the format of 20201231 with leap year check on the 29th of February

Submitted by anonymous - 6 years ago