Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?:(?:(?:0?[13578]|1[02])(\/)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/)(?:29|30)\2))(?:(?:19|[2-9]\d)\d{2})$|^(?:0?2(\/)29\3(?:(?:(?:19|20)(?:0[048]|[2468][048]|[13579][26]))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:19|[0-9]\d)?\d{2})$
/
gm

Description

This regex validates all dates between 1/1/1900 and 12/31/2099, including leap-year dates. It allows either one or two digit month/date values.

Submitted by anonymous - 5 years ago