Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^((?<leapFeb>(([13579]{1}[26]{1})|([02468]{1}[048]{1}))02(([0]{1}[1-9]{1})|([12]{1}[0-9]{1})))|(?<nonLeapYear>(?<anyYear>[0-9]{2})(?<nonLeapYearMonths>(?<all31DayMonths>([0]{1}[13578]{1}|[1]{1}[02]{1})(([0]{1}[1-9]{1})|([12]{1}[0-9]{1})|[3]{1}[01]{1}))|(?<all30DayMonths>([0]{1}[46]{1}|[1]{1}[1]{1})(([0]{1}[1-9]{1})|([12]{1}[0-9]{1})|[3]{1}[0]{1}))|(?<nonLeapYearFeb>02(([0]{1}[1-9]{1})|([1]{1}[0-9]{1})|([2]{1}[0-8]{1}))))))$
/
gm

Description

This expression validates any YYMMDD date, and insures that the leap year is accounted for. This is valid till 2099, 2100 is NOT a leap year.

Submitted by M. Fahmy - 2 days ago