Skip to content

Instantly share code, notes, and snippets.

@alex-gist
Forked from shreyas-satish/gist:1381897
Created March 12, 2012 16:47
Show Gist options
  • Save alex-gist/2023275 to your computer and use it in GitHub Desktop.
Save alex-gist/2023275 to your computer and use it in GitHub Desktop.
JavaScript: Date validator
function isValidDate(date) {
var matches = /^(\d{2})[-\/](\d{2})[-\/](\d{4})$/.exec(date);
if (matches == null) return false;
var d = matches[1];
var m = matches[2] - 1;
var y = matches[3];
var composedDate = new Date(y, m, d);
return composedDate.getDate() == d && composedDate.getMonth() == m && composedDate.getFullYear() == y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment