0

I have a strange problem with JQuery.validate

The forms validate fine, the errorClass works, but the custom messages don't come through I just get the generic ones.

I've checked the contents of stack exchange and it seems to be either typos or not specifying the name field in the html.

Can someone point me in the right direction here?

HTML

<form action="#" method="POST" id="vlanForm" name="vlanForm">
<div class="flip"><h3>Add VLAN</h3></div>
<div class="panel">
VLAN ID:<input type="text" id="vlan" name="vlan"><br>
<input type="submit" class="button" style="position: absolute;right: 7px;" name="vlanSubmit" value="Send"><br></div>
 </form>

Javascript

$("#vlanForm").validate({
    errorClass: 'wrong',
    rules: {
        vlan: {
            required: true,
            number: true
              },
    messages: {
        vlan: {
            required: "Please enter a vlan",
            number: "Number only please"
              }
           }
         }
});

As I say, the validation on the form works, the custom class works, but the messages don't, despite the name field being set on each. Apologies in advance if it is just a Typo I'm being blind on but I've looked over it many times.

1 Answer 1

1

Check your opening and closing of braces is not correct that's why you are facing the problem.

Syntax is:

rules:{

},
messages:{

}

your messages comes under rools, that's why custom messages are not showing

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

1 Comment

Thankyou. Of course. I'll accept your answer as soon as I can

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.