Validation is a jquery plug-in that provides a great way to simplify the validation of a form's work, as well as the general need for functionality. Rules are simple enough, easy to use, for a simple example, with validation to verify the registration form.
First, determine the objectives of the validation:
1. Required fields cannot be empty
2. The registered user name must be 6-12 characters characters
3. Qualified email format
4. The password must be 6-18 characters
5. Confirm password must be consistent with password
OK, the target is clear. Positive start
Copy Code code as follows:
<script type= "Text/javascript" src= ". /lib/jquery-1.3.2.min.js "></script>
<script type= "Text/javascript" src= ". /lib/jquery.validate.min.js "></script>
<script type= "Text/javascript" >
$ (function () {
$ ("#regForm"). Validate ({
Rules: {
Register User Name
Username: {
Required:true,
Minlength:5,
Maxlength:12
},
Email
Email: {
Required:true,
Email:true
},
Password
Password: {
Required:true,
Minlength:6,
Maxlength:18
},
Confirm Password
Confirm_password: {
Equalto: "#password"
},
Verification Code
CAPTCHA: {
Required:true,
Remote: "checkcaptcha.php"
}
},
Messages: {
Register User Name
Username: {
Required: "This item cannot be empty",
MinLength: "No less than 5 characters",
MaxLength: "No more than 12 characters"
},
Email
Email: {
Required: "This item cannot be empty",
Email: "Email format is not correct"
},
Password
Password: {
Required: "This item cannot be empty",
MinLength: "No less than 6 characters",
MaxLength: "No more than 18 characters"
},
Confirm Password
Confirm_password: "Two input passwords inconsistent",
Verification Code
CAPTCHA: {
Required: "Please enter the verification code",
Remote: "Validation code input Error"
}
}
});
});
</script>
After running, get the following results
More usage Reference http://www.jb51.net/article/24405.htm