Skip to content

Instantly share code, notes, and snippets.

@matiasleidemer
Created July 31, 2009 03:24
Show Gist options
  • Save matiasleidemer/159068 to your computer and use it in GitHub Desktop.
Save matiasleidemer/159068 to your computer and use it in GitHub Desktop.
function validateDateFormat(dateValue) {
var dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
var dateOK = true;
if (!dateValue.blank() ) {
if(!dateRegex.test(dateValue)) {
dateOK = false;
} else {
var d = new Date(dateValue.replace(dateRegex, '$2/$1/$3'));
var ok = ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) &&
(parseInt(RegExp.$1, 10) == d.getDate()) &&
(parseInt(RegExp.$3, 10) == d.getFullYear() ) ;
if (!ok) { dateOK = false; }
}
}
return dateOK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment