The validation plug-in is used for basic verification.
The three references from top to bottom are jquery ontology references, jquery-validation references, and jquery-validation error prompts references. Just like the autocomplete plug-in. After the validation plug-in is introduced into the project, we will find an extra one.
The validate method.
Syntax
$ ( 'Form' ). Validate ({ Rules :{}, errorshow: function (error, element ){}}) |
Parameter? |
Description |
Rules |
Returns the validation rules for the element. The specific rules and rule definitions are shown below. |
Errorshow |
If the verification fails, the prompt statement is returned. Errorshow can be modified |
Error |
Error message returned when verification fails |
Element |
Verified Element |
Note: The validate method can only verify the form element. However, we need to verify the input element, so we can only send the element to be verified to the form. Then we are talking about how to write the rules verification rules. Note: The username mail and others written below are all the name attributes of the input element. Element name: {verification rule, verification rule ...}
- Rules :{
-
- Username: {required: True, Minlength: 7 },
- mail: {required: true , email: true },
- password: {required: true , minlength: 6, maxlength: 6 },
- enterpassword: {required: true , failed to: Password },
- homepage: {required: true , URL: true },
- birthday: {required: true , Date: true },
- Xueya: {digits: True}
-
- },
For more verification rules, you can view the error information in the. js file.Note: to verify whether B is the same as a, you need to set the ID attribute for.
Personal write instance
<Head> <title> </title> <SCRIPT src = "jquery1.7.js" type = "text/JavaScript"> </SCRIPT> <SCRIPT src = "jquery-validation-1.9.0/jquery. validate. JS "type =" text/JavaScript "> </SCRIPT> <SCRIPT src =" jquery-validation-1.9.0/localization/messages_cn.js "type =" text/JavaScript "> </SCRIPT> <SCRIPT type = "text/JavaScript"> $ (document ). ready (function () {$ ('# form1 '). validate ({rules: {Username: {required: True, minlength: 7}, mail: {required: True, email: true}, password: {required: True, minlength: 6, maxlength: 6}, enterpassword: {required: True, failed to: Password}, homepage: {required: True, URL: true}, birthday: {required: True, Date: true}, xueya: {digits: true}, errorshow: function (error, element) {error. appendto (element. siblings ('span '))}})}) </SCRIPT>