0

I have separate input fields for month, day, and year. The current date regex does not account for leap years. I tried adding other regex to account for leap years but had no success. Your help is greatly appreciated.

var bmonth = Apperyio('register_birthdaymonth').val(); 
var bday = Apperyio('register_birthdayday').val(); 
var byear = Apperyio('register_birthdayyear').val(); 
var dateString = (bmonth + "/" + bday + "/" + byear)

var date_regex = /^(?:(0[1-9]|1[012])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](18|19|20)[0-9]{2})$/;
if (!(date_regex.test(dateString)))
{   
    errorMsg = errorMsg + "1";
    document.getElementById("bdayError").innerHTML = "Please enter your birthday.";
}
timmyusa
  • 29
  • 6

1 Answers1

0

Did you already look at this? Regular Expression | Leap Years and More

If not, try the following: (02)[\/.]29[\/.](((18|19|20)(04|08|[2468][048]|[13579][26]))|2000)

Community
  • 1
  • 1
WitchKing17
  • 185
  • 3
  • 21
  • When I replaced my current regex with the one you provided I received multiple errors including unexpected '/' How would I go about resolving this? – timmyusa Apr 14 '16 at 05:24