-
Notifications
You must be signed in to change notification settings - Fork 146
Options
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
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
Default: "default"
Theme name, used to set a theme style
Default: false
Whether to stop the continued validation when validation error
Default: true
Whether to automatically make the first mistake of the input box to get focus
Default: false
Whether to clear the message when the input box has focus
Default: false
When the field has no value, whether to ignore verification
Default: ""
Specify jQuery selector, the selected elements are ignored verified
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();
}
});
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;
}
});
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'
}
});
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;'
}
});
Collection of fields to be verified, the key is input name or # + input id. There are two ways:
- Pass a rule string:
"display: rule1;rule2;...rulen"
Whichdisplay:
is Optional, used to replace the{0}
of message string. - 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.
Callback before submiting the form.
Use dataFilter
, can convert the ajax results to niceValidator supported formats.
Callback after successful form validation.
Callback after failed form validation.
Theme Options
Default: "{0} is not valid."
Default error messages
Default: "Validating..."
Asynchronous loading tips
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.
Default: "n-valid"
When the field is valid, will add the class name to input box
Default: "n-invalid"
When the field is invalid, will add the class name to input box
Default: ":input"
pass a jqSelector to set the place where validClass or invalidClass binding to
Default: ""
Theme Styles namespace. Will add to form.
Default: ""
A class name that added to the message wrapper.
Default: ""
CSS styles that added to the message wrapper.
Default: "span"
The tag name of the message wrapper.
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>
Default: "<span class="n-icon"></span>"
Icon template.
Default: ""
Message arrow template.
Default: null
Message is displayed before the callback.
Default: null
Message is hidden before the callback.