The JQuery Validate plugin provides a powerful validation feature for forms, making it easier to validate client forms, while providing a number of customization options to meet the needs of your application. The plugin bundles a set of useful validation methods, including URL and email validation, and provides an API to write user-defined methods. All bundled methods use English as an error message by default and are translated into 37 other languages.
Import JS Library
<script src= "Http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js" ></script>
<script src= "Http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js" ></ Script>
Default validation rules
Serial Number |
rules |
Description |
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. |
How to use
1, Officer rules written into the control
<script src= "Http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js" ></script> < Script src= "Http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js" ></ script> <script src= "Http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_
Zh.js "></script> <script> $.validator.setdefaults ({submithandler:function () {alert (" Submit event! ");
}
});
$ (). Ready (function () {$ ("#commentForm"). Validate ();}); </script> <form class= "Cmxform" id= "Commentform" method= "Get" action= "" > <fieldset> <legend> Enter your name, email address, URL, and comment. </legend> <p> <label for= "CNAME" >name (required, minimum two letters) </label> <input id= "CNAME" NA Me= "Name" minlength= "2" type= "text" required> </p> <p> <label for= "Cemail" >e-mail (required) &
lt;/label> <input id= "cemail" type= "email" name= "email" required> </p> <p> <label for= "Curl" >url (optional) </label> <input id= "curl" type= "url" name= "url" > </p> <p> <label for= "Ccomment" > Remarks (Required) </label> <textarea id= "Ccomment" name=