Regular Expressions 101

Community Patterns

Date Validation - Including Leap Year (mm/dd/yyyy)

0

Regular Expression
ECMAScript (JavaScript)

/
^(?:(?:(?:0[13578]|1[02])(\/)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/)(?:29|30)\2))(?:(?:19|[2-9]\d)\d{2})$|^(?:02(\/)29\3(?:(?:(?:19|20)(?:[02468][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 01/01/1900 and 12/31/2099, including leap-year validation. It follows a mm/dd/yyyy format, and enforces two-digit month/year formats.

Submitted by anonymous - 5 years ago