Skip to content

Instantly share code, notes, and snippets.

@gotoark
Created August 23, 2017 07:14
Show Gist options
  • Save gotoark/953d66d75302588f5ecd80ef0a69fcb0 to your computer and use it in GitHub Desktop.
Save gotoark/953d66d75302588f5ecd80ef0a69fcb0 to your computer and use it in GitHub Desktop.
DateOfBirthValidation in JS
$(function() {
$(".datepicker").datepicker();
$("#dateOfBirth").change(function() {
var dob = $(this).datepicker("getDate");
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
$("#age").val(age);
//Check Minimum Age
if (age < 18) {
//alert("Age should be more than 18 years");
$("#age").val('');
$("#dateOfBirth").val('');
$("#errors").text('Age should be more than 18 years Provide Valid DateOfBirth');
return false;
}
//Check Maximum Age
if (age > 100) {
$("#age").val('');
$("#dateOfBirth").val();
$("#errors").text('Age should not more than 100 years Provide Valid DateOfBirth');
return false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment