Regex for Date DD-MM-YYYY

Posted by Josh M on Stack Overflow See other posts from Stack Overflow or by Josh M
Published on 2012-06-07T04:34:47Z Indexed on 2012/06/07 4:40 UTC
Read the original article Hit count: 128

Filed under:
|
|

I have the following expression which will be used as date validation in the HTML5 "pattern" attribute.

?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))-(?:(?:0[1-9]|1[0-2])-(?:19|20)[0-9]{2}

I want it to allow only valid dates, using "-" as a separator. This means up to 29th in February if it's a leap year, and 30/31 for other months respectively.

Currently, it only allows years starting with 2 (2012) and months up to 12 (December). But it limits the day to 29 regardless of which month.

Can anybody help me fix it?

© Stack Overflow or respective owner

Related posts about html

Related posts about regex