Skip to content

Instantly share code, notes, and snippets.

@mahfuzul
Created October 30, 2017 10:51
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 mahfuzul/bdd5bc69cb01fe3ead9989fbe1ec8f1f to your computer and use it in GitHub Desktop.
Save mahfuzul/bdd5bc69cb01fe3ead9989fbe1ec8f1f to your computer and use it in GitHub Desktop.
Validate age/date 18 years or not
// Validate DOB 18 years or not
jQuery.validator.addMethod( "stValidDOB", function(value, element) {
var dob = value.split("-");
var year = dob[0];
var month = dob[1];
var day = dob[2];
var age = 18;
var mydate = new Date();
mydate.setFullYear(year, month-1, day);
var currdate = new Date();
var setDate = new Date();
setDate.setFullYear(mydate.getFullYear() + age, month-1, day);
if ((currdate - setDate) > 0){
return true;
}else{
return false;
}
}, "Sorry, you must be 18 years of age to apply" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment