Jquery:validate Add custom validation
JQuery.validator.addMethod Add a custom validation rule
Addmethod:name, method, message
Simple instance: Add to a single validation
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>validate.js Expansion Verification </title>
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script type= "Text/javascript" src= "Jquery.validate.js" ></script>
<script type= "Text/javascript" src= "Validate.expand.js" ></script>
<body>
<form action= "" method= "Get" id= "tinyphp" >
<input type= "text" value= "" name= "Iszipcode"/>
<input type= "Submit" value= "submitted"/>
</form>
<script type= "Text/javascript" >
$ ("#tinyphp"). Validate ({
Adding validation rules
Rules: {
Iszipcode: {//Verify Mailbox
Iszipcode:true
}
}
});
</script>
</body>
Validate.expand.js
Copy Code code as follows:
JQuery.validator.addMethod ("Iszipcode", function (value, Element) {
var tel =/^[0-9]{6}$/;
return this.optional (Element) | | (Tel.test (value));
"Please fill in your zip code correctly");
Add multiple authentication Methods
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>validate.js Expansion Verification </title>
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script type= "Text/javascript" src= "Jquery.validate.js" ></script>
<script type= "Text/javascript" src= "Validate.expand.js" ></script>
<body>
<form action= "" method= "Get" id= "tinyphp" >
Post code: <input type= "text" value= "" Name= "Iszipcode"/><br/><br/>
Name: <input type= "text" value= "" name= "UserName"/>
<input type= "Submit" value= "submitted"/>
</form>
<script type= "Text/javascript" >
$ ("#tinyphp"). Validate ({
Adding validation rules
Rules: {
Iszipcode: {//Verify Mailbox
Iszipcode:true
},
username:{
Required:true,
Username:true,
Rangelength: [5,10]
}
},
Reset the hint information to omit
messages:{
UserName: {
Required: "Please fill in User name",
Rangelength: "User name must be between 5-10 characters"
}
}
});
</script>
</body>
Validate.expand.js
Copy Code code as follows:
JQuery.validator.addMethod ("UserName", function (value, Element) {
return this.optional (Element) | | /^[\u0391-\uffe5\w]+$/.test (value);
"User name must be between 5-10 characters");
JQuery.validator.addMethod ("Iszipcode", function (value, Element) {
var tel =/^[0-9]{6}$/;
return this.optional (Element) | | (Tel.test (value));
"Please fill in your zip code correctly");