I want to validate the birthday using a JavaScript. Birthday is given by a date field. Now I want to check whether the relevant person is older than 18 or not. How can I do it? I have created a function to check the age and now I want to invoke it in an another method and display proper error messages.
Here is my code
function validateDOB(){
var dob = $("[name ='dob']").val();
var bdYear, year;
bdYear = dob.substring(6, 10) - 0;
year = new Date().getFullYear();
if ((year - bdYear <= 18) && (year - bdYear >= 60)) {
return false;
} else {
return true;
}
$("#form").validate({
rules: {
dob: {
required: true,
}
}
});