JQuery validation plugin: how to create your own posts

I am using jquery validation plugin with php on ubuntu.

I apply validation for my forms as follows:

$(obj).find("form").validate();

When I set "email" as the class of any text field, and I give it the wrong email address, it shows the following error.

Please enter a valid email address.

Question: The message above is very long and will damage the alignment of my form and table. I want to use very short messages like this.

required
invalid email
invalid phone number
etc.

I tried this, but it shows its own messages, not mine.

$(obj).find("form").validate({

        messages: {
            required: "Required.",
            email: "Invalid email",
            url: "Invalid URL."
        }

    });

Can someone tell me how to do this? What is the exact code. The option "Messages" does not work for me. Thanks

+3
2

? , name input .

<form id="commentForm" method="get" action="">
    <fieldset>
        <input id="iname" name="nname" size="25" class="required" minlength="2" /><br />
        <input id="iemail" name="nemail" size="25"  class="required email" /><br />
        <input id="iurl" name="nurl" size="25"  class="url" /><br />
        <input class="submit" type="submit" value="Submit"/>
    </fieldset>
</form>

$(document).ready(function() {
    $("#commentForm").validate({
        messages: {
            nname: "Required",
            nemail: "Invalid email",
            ncomment: "Invalid URL"
        }
    });
});

$("#commentForm").validate({
    messages: {
        nname: "Required",
        nemail: {
            required: "Email needed",
            email: "Invalid email"
        },
        ncomment: "Invalid URL"
    }

});
+5
+1

Source: https://habr.com/ru/post/1725042/


All Articles