This article illustrates the jquery Validate form verification plug-in, how to customize a validation method, share for everyone to refer to, the specific content as follows
The effect is as follows:
Validation failure Effect:
To verify successful results:
Specific steps:
1, the introduction of the dependency package
<script src= ". /.. /scripts/jquery-1.3.1.js "type=" Text/javascript "></script>
<script src=" Lib/jquery.validate.js " Type= "Text/javascript" ></script>
2, add error style and success style
em {font-weight:bold; padding-right:1em; vertical-align:top;}
Em.error {
Background:url ("images/unchecked.gif") no-repeat 0px 0px;
padding-left:16px;
}
em.success {
Background:url ("images/checked.gif") no-repeat 0px 0px;
padding-left:16px;
}
3. Customize a validation method
Customize a validation method
$.validator.addmethod (
"formula",//validation method name
function (value, element, param) {//validation rules
return value = = eval (param);
},
' Please enter the result of the math formula calculation correctly '///Verify the hint information
);
4. Call Style display
Errorelement: "em", //used to create error message label
success:function (label) { //Verify successful execution of callback function
// The label points to the above error message label em
label.text ("") //Empty error prompt messages
. addclass ("Success"); Add a custom success class
}
5, detailed code as follows
This article has been organized into the "jquery form verification Encyclopedia," Welcome to learn to read.
The above is the entire content of this article, I hope to learn form verification to help you.