Skip to content
niceue edited this page Oct 5, 2014 · 10 revisions

debug Number | Boolean]

Default: 0
Whether to enable debug mode, the available values:
0: Close debugging information
1: Enable debug information
2: Enable debug information, and regardless of the form to verify that success would submit the form, to facilitate comparison of the back-end verification

timely Number | Boolean

Default: 1
Whether to enable real-time validation, the available values:
0: Off the real-time verification, will only be validated when the form is submitted
1: Enable real-time validation, field will be validated when focusout
2: Enable real-time validation, validate the field while inputing

theme String

Default: "default"
Theme name, used to set a theme style

stopOnError Boolean

Default: false
Whether to stop the continued validation when validation error

focusInvalid Boolean

Default: true
Whether to automatically make the first mistake of the input box to get focus

focusCleanup Boolean

Default: false
Whether to clear the message when the input box has focus

ignore jqSelector

Default: ""
Specify jQuery selector, the selected elements are ignored verified

display display(element)

Custom the name to replace the {0} in a message

rules Object

Custom rules for the current instance

$('form').validator({
    rules: {
        // Custom validation function
        myRule: function(el, param, field){
            //do something...
        },
        // Configuration regular and error messages
        another: [/^\w*$/, 'Please enter the letters or underscore.']
    },
    fields: {
        // Call two rules previously defined
        foo: 'required; myRule[param]; another'
    }
});

messages Object

Custom messages for the current instance

$('form').validator({
    messages: {
        required: "Please fill in this field",
        email: "Please enter a valid email address.",
    },
    fields: {
        'email': 'required;email;'
    }
});

fields Object

Collection of fields to be verified, the key is input name or # + input id. There are two ways:

  1. Pass a rule string: "display: rule1;rule2;...rulen" Which display: is Optional, used to replace the {0} of message string.
  2. Pass a object:
fields: {
    name: {
        rule: "name: required; rule2; rule3",
        msg: {
            required: "Please fill in your name",
            rule2: "{0} xxxx",
            rule3: "{0} xxxx"
        },
        tip: "Fill real name can help a friend find you",
        ok: "",
        timely: false,
        target: "#msg_holder"
    },
    email: "required; email",
    mobile: "mobile"
}

fields[key].rule String
Field validation rules, more rules with a semicolon ; separated, support the use of square brackets [] or parentheses () the Senate

fields[key].msg String | Object

fields[key].tip String

fields[key].ok String

fields[key].display String | Function

fields[key].msgWrapper String

fields[key].msgMaker Function

fields[key].msgClass String

fields[key].msgStyle String

fields[key].dataFilter Function

fields[key].valid Function

fields[key].invalid Function

fields[key].must Boolean

fields[key].timely Number | Boolean

fields[key].target String

beforeSubmit beforeSubmit(form)

Callback before submiting the form.

dataFilter dataFilter(data)

Use dataFilter, can convert the ajax results to niceValidator supported formats

valid valid(form)

Callback after successful form validation.

invalid invalid(form, errors)

Callback after failed form validation.


Theme Options


defaultMsg String

Default: "{0} is not valid."
Default error messages

loadingMsg String

Default: "Validating..."
Asynchronous loading tips

showOk String | Boolean

Default: true
Whether to show success tips (Note: the premise is that had pass ok parameter). If set to false, will simply hidden messages. If you pass a string, the validation is successful, it will prompt the message, if set to an empty string, will show only a successful icon.

validClass String

Default: "n-valid"
When the field is valid, will add the class name to input box

invalidClass String

Default: "n-invalid"
When the field is invalid, will add the class name to input box

formClass String

Default: ""
Theme Styles namespace. Will add to form.

msgClass String

Default: ""
A class name that added to the message wrapper.

msgStyle String

Default: ""
css styles that added to the message wrapper.

msgWrapper String

Default: "span"
The tag name of the message wrapper.

msgMaker msgMaker(obj)

Default: internal
Message maker, can be used to customize the message structure.
The following code:

$('#form').validator({
    fields: {
        'user[name]': 'required;username'
        ,'user[pwd]': 'required;password'
    },
    msgWrapper: 'div',
    msgMaker: function(opt){
        return '<span class="'+ opt.type +'">' + opt.msg + '</span>';
    }
});

Finally automatically generated message is:

<div class="msg-box n-right" for="user[name]">
    <span class="n-error">Please fill this field.</span>
</div>

msgIcon String

Default: "<span class="n-icon"></span>"
Icon template.

msgShow msgShow($msgbox, type)

Default: null
Message is displayed before the callback.

msgHide msgHide($msgbox, type)

Default: null
Message is hidden before the callback.

Clone this wiki locally