Skip to content

Instantly share code, notes, and snippets.

@carcus88
Created January 25, 2017 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carcus88/74628a94bc135a2c8957af7474c177d3 to your computer and use it in GitHub Desktop.
Save carcus88/74628a94bc135a2c8957af7474c177d3 to your computer and use it in GitHub Desktop.
validate a date string in javascript
function isValidDate(date) {
var parts = date.split('/');
var month = parts[0];
var day = parts[1];
var year = parts [2];
year = Number(year);
month = Number(month);
day = Number(day)
var d = new Date(date);
if (d.getFullYear() != year
|| (d.getMonth() + 1) != month
|| d.getDate() != day) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment