jquery validation only digits

南楼画角 提交于 2019-12-30 02:48:09

问题


I am having the jquery.validate.js plugin and it is working fine for me.

My question is :

I am having a textbox and this textbox is mandatory and should only accept digits.

In the js, I can see that there is validation for the digits and the problem is that I do not know how to use it.

I only knew how to make the field required by putting in the textbox field <class="required">

So, how can I add one more validation criteria to accept only digits.

Thanx


回答1:


to check it add

$("#myform").validate({
  rules: {
    amount: {
      required: true,
      digits: true
    }
  }
});

http://docs.jquery.com/Plugins/Validation/Methods/digits




回答2:


$("#mobile_number").validate({
            rules: {

                mobile_number: {required: true,number:true}
            },
            messages: {
                mobile_number: {required: "Please Enter Your Mobile Number",number:"Please enter numbers Only"}
            }

 });


来源:https://stackoverflow.com/questions/3456382/jquery-validation-only-digits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!