Validating form entries with jquery validate in Web pages

Source: Internet
Author: User

I rookie, W3cschool on the things, feel very good.

Import Library

<script src= ". /js/jquery.js "type=" Text/javascript "></script><script src=". /js/jquery.validate.js "type=" Text/javascript "></script>

The default rule is basically enough,

1 Required:true The field that must be entered.
2 Remote: "check.php" Use the Ajax method to call check.php to validate the input values.
3 Email:true You must enter an e-mail message in the correct format.
4 Url:true You must enter a URL in the correct format.
5 Date:true You must enter a date in the correct format. Date Check IE6 error, use with caution.
6 Dateiso:true You must enter the correct format for the date (ISO), for example: 2009-06-23, 1998/01/22. Verify the format only and do not validate the validity.
7 Number:true You must enter a valid number (negative, fractional).
8 Digits:true You must enter an integer.
9 CreditCard You must enter a valid credit card number.
10 Equalto: "#field" The input value must be the same as #field.
11 Accept Enter a string with a valid suffix name (the suffix of the upload file).
12 Maxlength:5 Enter a string with a maximum length of 5 (Chinese characters are counted as one character).
13 Minlength:10 Enter a string with a minimum length of 10 (Chinese characters are counted as one character).
14 RANGELENGTH:[5,10] Enter a string that must be between 5 and 10 (Chinese characters are counted as one character).
15 RANGE:[5,10] The input value must be between 5 and 10.
16 Max:5 The input value cannot be greater than 5.
17 Min:10 The input value cannot be less than 10.

The focus is on two ways of using

1, write to class in the need to introduce this JS

<script src= ". /js/jquery.metadata.js "type=" Text/javascript "></script>
Add in HTML
<input id= "password" name= "password" type= "password" class= "{required:true,minlength:5}"/>

Write first

$ (). Ready (function () {$ ("#signupForm"). Validate ();});

I use the object's way, so the Name property is OBJECT.PR so the second way to find out is no, he uses the name attribute to find, should be.

2, write to JS

$ (). Ready (function () {$ ("#signupForm"). Validate ({rules: {firstname: "required", email: {required:true, Email:true}, Password: {required:true, minlength:5}, Confirm_password: {required:true, Minl    Ength:5, Equalto: "#password"}, messages: {firstname: "Please enter your name", email: {Required: "Please enter your email address", Email: "Please enter the correct email address"}, Password: {required: "Please enter a password", Minlength:jQuery.format ("Password cannot be less than {0} characters")}, Conf Irm_password: {required: "Please enter confirmation password", minlength: "Confirm password cannot be less than 5 characters", Equalto: "Two times input password inconsistent inconsistent"}}); Messages, if a control does not have a message, the default information is called <form id= "Signupform" method= "Get" action= "" > <p> <label for= "FirstName" >Firstname</label> <input id= "FirstName" name= "FirstName"/> </p> <p> &lt Label for= "Email" >E-Mail</label> <input id= "email" name= "email"/> </p> <p> <label for= " Password ">password</label> <input id= "password" name= "password" type= "password"/> </p> <p> <label for= "Confirm_password" > Confirm Password </label> <input id= "Confirm_password" name= "Confirm_password" type= "password"/> </p> <p > <input class= "Submit" type= "submit" value= "Submit"/> </p></form>

The above is a copy of the content. For more information, please visit http://www.w3cschool.cc/jquery/jquery-plugin-validate.html

Validating form entries with jquery validate in Web pages

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.