Created
August 23, 2017 07:14
-
-
Save gotoark/953d66d75302588f5ecd80ef0a69fcb0 to your computer and use it in GitHub Desktop.
DateOfBirthValidation in JS
This file contains 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
$(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