Juquery Validation Plugin validation Addmethod method use notes

Source: Internet
Author: User

The method has three API interface parameters, Name,method,messages

Addmethod (Name,method,message) method

The parameter name is the name of the method added.

The parameter method is a function that receives three parameters (Value,element,param).
Value is the value of an element, which is the element itself, and param is a parameter.

We can use Addmethod to add validation methods other than the built-in Validation method. For example, there is a field, can only lose one letter, the range is a-f, the wording is as follows:

$.Validator.Addmethod("AF",function(Value,Element,Params){ If(Value.Length>1){Return False;} If (value>=params[< Span class= "lit" >0] && Value<=params[1) { return true;}else{return  false;}}, "must be a letter and a-f"    

If there is a id= "username" for a form field, write in the rules:

Username: {   af: ["A","F"]}       

The first parameter of the Addmethod is the name of the added validation method, which is AF.

The second parameter of the Addmethod is a function, which is more important and determines how to use this validation method.


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

If there is only one parameter, write directly, such as AF: "A", then A is the only parameter, if multiple parameters, then write in [], separated by commas.

Juquery Validation Plugin validation Addmethod method use notes

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.