Skip to content
Jony edited this page Jan 27, 2016 · 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 input
3: Enable real-time validation, field will be validated when input and focusout

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

ignoreBlank Boolean

Default: false
When the field has no value, whether to ignore verification

ignore jqSelector

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

display display(element)

Custom the display name to replace the {0} in message string

$('form').validator({
    display: function(element){
        return $(element).closest('.form-item').children('label:eq(0)').text();
    }
});

target target(element)

Use function to dynamically obtain target

$('form').validator({
    target: function(element){
        var $formitem = $(element).closest('.form-item'),
            $msgbox = $formitem.find('span.msg-box');
        if (!$msgbox.length) {
            $msgbox = $('<span class="msg-box"></span>').appendTo($formitem);
        }
        return $msgbox;
    }
});

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
Custom fields for each rule error message

fields[key]. tip String
Custom friendly tip when the field is focus.

fields[key]. ok String
Custom friendly message when the field is valid.

fields[key]. display String | Function
Custom the display name to replace the {0} in message string

fields[key]. msgWrapper String
The tag name of the message wrapper.

fields[key]. msgMaker Function
Message maker, can be used to customize the message structure.

fields[key]. msgClass String
A class name that added to the message wrapper.

fields[key]. msgStyle String
CSS styles that added to the message wrapper.

fields[key]. dataFilter Function
Use dataFilter, can convert the ajax results to niceValidator supported formats.

fields[key]. valid Function
Callback after successful field validation.

fields[key]. invalid Function
Callback after failed field validation.

fields[key]. must Boolean
Whether to mandatory verify the field.

fields[key]. timely Number | Boolean
Whether to enable real-time validation.

fields[key]. target String
Verify the current field, but in fact prompts an error message on the target element.

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

bindClassTo String

Default: ":input"
pass a jqSelector to set the place where validClass or invalidClass binding to

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.

msgArrow String

Default: ""
Message arrow 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.