开发者

Validating the age limit using jquery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜