jQuery Validation plugin - Custom message

Detonator picture Detonator · Jul 21, 2011 · Viewed 52.2k times · Source

I am new to JQuery and am using the JQuery validation plugin.

I would like to ask, how to override the default messages to display also text in label associated with form element.

I would get message something like this:

Field Password is required. instead of default This field is required.

Field PostCode must contain at least 3 characters. instead of default Please enter at least 3 characters.

I need to override the default behaviour of this plugin, because I do not want to specify custom message for each item for every type of validation.

Is it possible?

Answer

Shef picture Shef · Jul 21, 2011
$("#signupform")
    .validate({
        rules: {
            password: "required",
            postcode: {
                required: true,
                minlength: 3
            }
        },
        messages: {
            password: "Field Password is required",
            postcode: {
                required: "Field PostCode is required",
                minlength: "Field PostCode must contain at least 3 characters" 
            }
    });