Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^(\d{4})-((02-(0[1-9]|[12]\d))|((0[469]|11)-(0[1-9]|[12]\d|30))|((0[13578]|1[02])-(0[1-9]|[12]\d|3[01])))$
/

Description

This pattern validates all the possible dates for all months in YYYY-MM-DD format. Due to limitations of regex it can not validate the dates of february for leap year. It will allow the date 29 for leap year too. Make sure to validate that yourself.

Submitted by Ashutosh Agrawal - 9 years ago