开发者

Validating the age limit using jquery

开发者 https://www.devze.com 2022-12-25 00:20 出处:网络
How to ch开发者_如何学编程eck whether the entered age is between the specific limit, using Jquery in html formsUse the jquery validate library http://docs.jquery.com/Plugins/Validation/ you can take a

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消