user1554264
user1554264

Reputation: 1224

How to fix jQuery Validation on multiple fields

I am trying to validate the input element with the id of phone, I have already validated the input element postcode successfully with required and minlength.

I have attached the second input field called number and the rules required and number, but it is not validating that the input into the form is a number. It is running the required check, but when I enter a letter the form allows this, which is not what I want it to do.

Please find the form here - http://www.bestclownintown.co.uk/book.php

here is the jQuery code, could my syntax be wrong? Any help is appreciated:

 <script>
      $(document).ready(function() {
          $("#myform").validate({
              rules: {
               postcode: {required: true, minlength: 6},
               number: {required: true, number: true},        
              }
          });
      });
  </script>

Upvotes: 1

Views: 126

Answers (1)

servik
servik

Reputation: 3111

Try to replace your code with this:

  $(document).ready(function() {
      $("#myform").validate({
          rules: {
           postcode: {required: true, minlength: 6},
           phone: {required: true, number: true},        
          }
      });
  });

key for rules object should be name, class or attribute of validating element. For more info consult with docs.

Upvotes: 1

Related Questions