cgoodman
Programmer
- Dec 29, 2008
- 7
I have written this leap year regex and checked it with the year 2099 and have gotten incorrect results. Here is my regex:
Thanks for any help.
Code:
if((Year%4)==0 && (Year%100 != 0 || Year%400 == 0))
{
ISLEAPYEAR = 1;
}
# Regular expression check, checks each month individually, due to differences in numbers of days/month. Also does leap year check for the possiblity of 02/29
if((ISLEAPYEAR == 1 && Date !~ "(0[13578]|1[02])(/)(0[1-9]|[12][0-9]|3[01])(/)(18|19|20)[0-9][0-9]" && Date !~ "(02)(/)(0[1-9]|[12][0-9])(/)(18|19|20)[0-9][0-9]" && Date !~ "(0[4689]|11)(/)(0[1-9]|[12][0-9]|30)(/)(18|19|20)[0-9][0-9]" && Date != "") ||
(ISLEAPYEAR == 0 && Date !~ "(0[13578]|10|12)(/)(0[1-9]|[12][0-9]|3[01])(/)(18|19|20)[0-9][0-9]" && Date !~ "(02)(/)(0[1-9]|1[0-9]|2[0-8])(/)(18|19|20)[0-9][0-9]" && Date !~ "(0[4689]|11)(/)(0[1-9]|[12][0-9]|30)(/)(18|19|20)[0-9][0-9]" && Date != ""))
Thanks for any help.