# Valid dates on regular expression

In Gregorian calendar, if a year is divisible by 400 then it is a leap year. 2000 is a leap year where 2100 is not. how would you implement (if year % 400 == 0) using only regular expression constructs? implementation using if else statement would be considered invalid since this will be dealt with externally. the solution will validate if February has 28 or 29 days. My problem deals with 4 digit year (from 1000) but any guide to a general solution will also be very helpful.

Try This Regex

It will match a leap year.

```((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))\$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))\$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))\$)|(^(0?2)([/])(29)([/])([2468][048]00)\$)|(^(0?2)([/])(29)([/])([3579][26]00)\$)|(^(0?2)([/])(29)([/])([1][89][0][48])\$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])\$)|(^(0?2)([/])(29)([/])([1][89][2468][048])\$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])\$)|(^(0?2)([/])(29)([/])([1][89][13579][26])\$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])\$))
```

It will match

mm/dd/yyyy,m/dd/yyyy,mm,d/yyyy and m/d/yyyy

Check Here