Jquery.validate is a validation framework for jquery, with the advantage of jquery, we can quickly verify some of the common input, and we can expand our own authentication methods, and international also have good support.
The normal authentication mode is as follows:
<form id= "ff" action= "XXX" > ...
<input type= "Submit" value= "Submission" >
</form>
[Java] View plaincopy see the code on the codes derived from my Code slice
So just click on the Submit button and the plugin will be validated automatically.
But sometimes we want to click on the other buttons to verify the form, and then do the rest based on the validation results of the form.
See the source found that there is a form () method, this method is to perform the validation operation, although the method literal meaning is not very consistent.
Then we can do this:
Var validator;//declares a global variable
$ (function () {
validator = $ (' #ff '). Validate ();//This sentence returns an object
})
function Add () {
var b = validator.form ();//Return a Boolean value
if (b) {//Verify success
//Do add ...
}
}
If validation fails, an error message is displayed, and if you want to clear the error message, you can call Validator.resetform ();
With the Validator.form () and Validator.resetform () Two methods , we can use the verification plugin flexibly.
Validating fields
required– Required Fields
remote– Remote Authentication
minlength– Minimum Length verification
maxlength– Maximum length verification
rangelength– Length Range Verification
min– Minimum Value verification
max– max value Verification
range– Range Value Validation
email– Email Address Verification
Url–url Address Verification
date– Date Validation
Dateiso–iso Date Format Validation
number– decimal Number Verification
digits– Digital Verification
creditcard– Credit card number verification
Value equality validation for equalto– and another text box