1

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>
0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you sigurd this has fixed the problem. Should I leave the code in my question above unchanged so that people may reference to it?
The best option for you is to leave your code as is and accept the answer that was helpful for you personally. This will help other peolpe to see what was the problem and what is the possible solution for the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.