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