How to ch开发者_如何学编程eck whether the entered age is between the specific limit, using Jquery in html forms
Use the jquery validate library http://docs.jquery.com/Plugins/Validation/ you can take a look there
$("#myform").validate({
rules: {
field: {
required: true,
rangelength: [2, 6]
}
}
});
Something like this should work:
$('input#age').change(function() {
var age = parseInt($(this).val(), 10);
if(age < 18 || age > 65) {
alert("Wrong age!");
}
});
Adjust as necessary.
精彩评论