JQuery Validate Chinese API attached validate.js Chinese API manual

Source: Internet
Author: User
Tags api manual manual wrapper

Name
return type
Describe

Validate (Options)
Return: Validator
Verify the selected form

Valid ()
Back: Boolean
Check to see if validation passes

Rules ()
Back: Options
Returns the validation rule for an element

Rules ("Add", rules)
Back: Options
Adding validation rules

Rules ("Remove", rules)
Back: Options
Delete validation rules

Removeattrs (attributes)
Back: Options
Delete Special properties and return them

Custom Selectors

: Blank
Return: Validator
Filter with no value

: Filled
Back: Array <element >
A filter with a value

: Unchecked
Back: Array <element >
Filters for elements that are not selected

Utilities

Jquery.format

(Template,argument, Argumentn ...)
Back: String
Replace {n} in template with a parameter

Validator

The Validate method returns a validator object, which has a number of methods that allow you to use the trigger checker or change the contents of the form. There are many ways to validator objects, but the following are just a list of commonly used

Form ()
Back: Boolean
Verify that the form returns success or failure

Element (Element)
Back: Boolean
To verify that a single element succeeds or fails

Resetform ()
return: undefined
Restores the previously validated form to the
Previous status prior to validation

ShowErrors (Errors)
return: undefined
Display a specific error message


Validator functions:

SetDefaults (defaults)
return: undefined
Change the default settings

Addmethod (Name,method,message)
return: undefined
Add a new authentication method.
Must include a unique
Name, a Web page special effects method and
A default message

Addclassrules (Name,rules)
return: undefined
Add combination validation type in a class
The surface is more useful in a variety of verification methods

Addclassrules (Rules)
return: undefined
Add combination validation type in a class
There are a number of verification methods in the
Use, this is a sudden add more

Built-in authentication method:

Required ()
Back: Boolean
Required validation Elements

Required (dependency-expression)
Back: Boolean
Required elements depend on the result of an expression

Required (Dependency-callback)
Back: Boolean
Required elements depend on the result of the callback function

Remote (URL)
Back: Boolean
Request a remote checksum. A URL is usually a
Remote Invoke method

MinLength (length)
Back: Boolean
Set Minimum Length

MaxLength (length)
Back: Boolean
Set Maximum length

Rangelength (Range)
Back: Boolean
Set a length range [Min,max]

Min (value)
Back: Boolean
Set maximum value

Max (value)
Back: Boolean
Set minimum value

Email ()
Back: Boolean
Verify e-mail format

Range (range)
Back: Boolean
Set the range of values

URL ()
Back: Boolean
Validate URL format

Date ()
Back: Boolean
Validate date format (similar to 30/30/2008 format, do not validate date accuracy only validate format)

Dateiso ()
Back: Boolean
Verify the ISO type date format

Datede ()
Back: Boolean
Verify the German date format (29.04.1994 or 1.1.2006)

Number ()
Back: Boolean
Verify decimal digits (including decimals)

Digits ()
Back: Boolean
validating integers

CreditCard ()
Back: Boolean
Verify credit card number

Accept (extension)
Back: Boolean
A string that validates the same suffix name

Equalto (Other)
Back: Boolean
Verify that the contents of the two input boxes are the same

Phoneus ()
Back: Boolean
Verify American phone numbers

Options for Validate ():

Debug: Debug mode (Form not submitted):
$ (". Selector"). Validate

({

Debug:true

})

Set Debug to Default:
$.validator.setdefaults ({

Debug:true

})

Submithandler:

A function that is run after validation is added to the form, or the form will not be submitted
$ (". Selector"). Validate ({

Submithandler:function (form) {

$ (form). Ajaxsubmit ();

}

})

Ignore

No validation for some elements
$ ("#myform"). Validate ({

Ignore: ". Ignore"

})

Rules

Custom rule, key:value form, key is the element to be validated, value can be a string or object
$ (". Selector"). Validate ({

rules:{

Name: "Required",

email:{

Required:true,

Email:true

}

}

})

Messages

Custom message Key:value The form key is the element to validate, the value is a string or a function
$ (". Selector"). Validate ({

rules:{

Name: "Required",

email:{

Required:true,

Email:true

}

},

messages:{

Name: "Name cannot be empty",

email:{

Required: "e-mail cannot be empty",

Email: "E-mail address is not correct"

}

}

})

Groups Tutorial:

Validation of a set of elements, using an error placement to control where the error message is placed
$ ("#myform"). Validate ({

groups:{

Username: "FName lname"

},

Errorplacement:function (error,element) {

if (element.attr ("name") = = "FName" | | element.attr ("name") = = "LName")

Error.insertafter ("#lastname");

Else

Error.insertafter (Element);

},

Debug:true

})

Onubmit Boolean default: True

Whether to validate when submitting
$ (". Selector"). Validate ({

Onsubmit:false

})

Onfocusout Boolean default: True

Whether to validate when focus is obtained
$ (". Selector"). Validate ({

Onfocusout:false

})

onkeyup Boolean default: True

Do you want to verify when tapping the keyboard
$ (". Selector"). Validate ({

Onkeyup:false

})

OnClick Boolean default: True

Whether to verify on mouse clicks (General validation Checkbox,radiobox)
$ (". Selector"). Validate ({

Onclick:false

})

Focusinvalid Boolean default: True

When a form is submitted, a form that is not validated (the first or the failed validated form that has the focus before it is submitted) receives the focus
$ (". Selector"). Validate ({

Focusinvalid:false

})

Focuscleanup Boolean default: False

When the element that is not validated gets the focus, the error message is removed (avoid and focusinvalid. Used together)
$ (". Selector"). Validate ({

Focuscleanup:true

})

Errorclass string Default: "Error"

To specify the CSS tutorial class name for the error hint, you can customize the style of the error hint
$ (". Selector"). Validate ({

Errorclass: "Invalid"

})

Errorelement string Default: "Label"

What tags are used to mark errors
$ (". Selector"). Validate

Errorelement: "em"

})

Wrapper string

What label do you use to wrap up the top errorelement?
$ (". Selector"). Validate ({

Wrapper: "Li"

})

Errorlabelcontainer Selector

Put the error message together in a container
$ ("#myform"). Validate ({

Errorlabelcontainer: "#messagebox",

Wrapper: "Li",

Submithandler:function () {alert ("submitted!")}

})


ShowErrors:

With a function, you can show how many elements are not validated in total
$ (". Selector"). Validate ({

Showerrors:function (errormap,errorlist) {

$ ("#summary"). HTML ("Your form contains" + this.numberofinvalids () + "Errors,see details below.");

This.defaultshowerrors ();

}

})

Errorplacement:

With a function, you can customize where the error is placed
$ ("#myform"). Validate ({

Rrorplacement:function (error,element) {error.appendto (Element.parent ("TD"). Next ("TD");

},

Debug:true


})

Success

The element to be validated is validated by the action, if followed by a string, as a CSS class, can also be followed by a function
$ ("#myform"). Validate ({

Success: "Valid",

Submithandler:function () {alert ("submitted!")}

})

Highlight:

You can add effects to an element that is not validated, flicker, etc.

Addmethod (Name,method,message) method:

Parameter name is the name of the method you added

Parameter method is a function that receives three arguments (Value,element,param) value is the value of the element, the element is the param itself is a parameter, and we can use Addmethod to add the addition built-in validation Verification methods other than methods such as a field, can only lose a letter, the range is a-f, written as follows:


$.validator.addmethod ("AF", function (value,element,params) {

if (value.length>1) {

return false;

}

if (Value>=params[0] && value<=params[1]) {

return true;

}else{

return false;

}

}, "must be a letter, and a-f");

When used, such as the id= "username" of a form field, it is written in the rules

username:{

Af:["A", "F"]

}


The first argument to Addmethod is the name of the added authentication method, which is the AF

The third parameter of Addmethod is the custom error prompt, where the prompt is: "must be a letter, and A-f"

The second parameter of the Addmethod is a function, which is more important and determines the way in which this validation method is written.

If only one argument is written directly, if AF: "A", then A is the only parameter, if multiple arguments are used in [], separated by commas

Meta String Method:

$ ("#myform"). Validate ({

Meta: "Validate",

Submithandler:function () {alert ("submitted!")}

})

<script type= "Text/javascript" src= "Web Effects/jquery.metadata.js" ></script>

<script type= "Text/javascript" src= "Js/jquery.validate.js" ></script>

<form id= "MyForm" >

<input type= "text" name= "email" class= "{validate:{required:true,email:true}}"/>

<input type= "Submit" value= "Submit"/>

</form>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.