Reference: http://www.runoob.com/jquery/jquery-plugin-validate.html
Http://www.cnblogs.com/artech/archive/2012/06/17/client-validation-01.html
Reference file:
<script type= "Text/javascript" src= "~/scripts/jquery-1.9.1.min.js" ></script>
<script src= "~/scripts/jquery.validate.min.js" ></script>
jquery Code:
$ (document). Ready (function () { $ ("form"). Validate (); });
HTML code:
@using (Html.BeginForm ("Addsave", "Articlesinfo", FormMethod.Post, new {enctype = "multipart/form-data", id = "Form1"})) {<table width= "100%" border= "0" align= "center" cellpadding= "0" cellspacing= "0" > <tr> <TD style= "width:100px" > title </td> <td> @Html. textboxfor (model = model. Title, new {@class = "Boxtext Required"}) </td> </tr> <tr> <td style= "width:100px" > matching diagram </td> <td> <input type= "File" Name= "Img" class= "Boxtext required"/> </td> ; </tr> <tr> <td style= "width:100px" > Content </td> <td> @Html. textareafor (model = model.Contents, new {cols = "", "rows =", "sign =" Contents ", @class =" Required "}) </td> </tr> <tr> <td> </td> <td> <input type= "Submit" value= "Save" class= "Boxbut"/> </td> </tr> </table>}
Custom rules and error messages
$ (document). Ready (function () { $ ("form"). Validate ({ rules: { Title: {required:true}, Img: { Required:true} }, messages: { title: {Required: "Please enter title"}, Img: {required: "Please select Picture"} } );
});
Default Check rule:
| 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. |
Jquery.validate.js Client Authentication