jquery validation only digits

97,694

Solution 1

to check it add

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

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

Solution 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"}
            }

 });
Share:
97,694
maas
Author by

maas

Updated on September 08, 2020

Comments

  • maas
    maas over 3 years

    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