Skip to content

Instantly share code, notes, and snippets.

@matthewnitschke
Last active March 9, 2017 23:07
Show Gist options
  • Select an option

  • Save matthewnitschke/136419dd7a017c7832a8786ed649f86a to your computer and use it in GitHub Desktop.

Select an option

Save matthewnitschke/136419dd7a017c7832a8786ed649f86a to your computer and use it in GitHub Desktop.
IE happy date check
function validDate(date){
var re = /(.{2})\/(.{2})\/((.{4})|(.{2}))/;
if (date.search(re) == -1){
return false;
}
var dt = date.split("/");
// month must be less than 13, greater than 0
var month = dt[0];
if (parseInt(month) > 12 || parseInt(month) < 1) {
return false;
}
var year = dt[2];
// day must be 2 digits, less than that months days, and greater than 0
var day = dt[1];
var daysInMonth = new Date(year, month, 0).getDate();
if (parseInt(day) > daysInMonth || parseInt(day) < 1){
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment