Regex for Date DD-MM-YYYY
- by Josh M
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?