Use jquery validate to validate the registration form instance Demo _jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.