Created
October 30, 2017 10:51
-
-
Save mahfuzul/bdd5bc69cb01fe3ead9989fbe1ec8f1f to your computer and use it in GitHub Desktop.
Validate age/date 18 years or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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