This article mainly introduces the support ASP.net MVC, webfrom form Verification Framework Validationsuar use introduction, this article explained the use step in detail, and gives a complete demo download, needs the friend to be possible to refer to under
1, support JavaScript side and back-end dual authentication (front-end is currently dependent on jquery.validate.js, can also be self expansion)
2, Code Concise
3. Easy to call
4. Full function
How to use:
Create a new initialization class that initializes all of the classes that need to be validated, and the syntax is fairly concise and can be managed uniformly, and your verification of this class completes 70%.
Function Description:
Add default type (mail, cell phone, QQ, etc.)
Addregex regular verification in add cannot satisfy the subordinates to use
Addfunc use JS function for verification, generally used in industry logic verification, function is very powerful, can meet a variety of verification (note: Addfunc function verification After the background needs to be validated, so you can use the two methods to verify, as far as possible using the above)
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The |
|
Global.cs Registration, we can use it.
Validation in most cases divided into two types
1, submit the submission of the wording
Register one line of code to get the binding information to ViewBag
Postregister is also a line to complete background validation
View
1. Refer to JS and write initialization function
2, put @html.raw (Viewbag.validationbind) at the bottom of the page
View complete code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 The 96 97 98 99 100 101 102 103 104 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
@{viewbag.title = "Register"; Layout = null; } <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Content-type" content= "text/" html Charset=utf-8 "/> <script src=/content/jquery-validation-1.13.1/lib/jquery-1.9.1.js" type= "Text/javascript" ></script> <script src= "/content/jquery-validation-1.13.1/dist/jquery.validate.js" type= "text/ JavaScript "></script> <script src="/content/validation.sugar.js "type=" Text/javascript "></ script> <script src= "/content/jquery-validation-1.13.1/lib/jquery.form.js" type= "Text/javascript" ></ script> <link href= "/content/jquery-validation-1.13.1/validation.sugar.css" rel= "stylesheet" type= "Text/css" /> <script type= "Text/javascript" > $ (function () {var factory = new Validatefactory ($ ("form"), "<img src="/co Ntent/jquery-validation-1.13.1/error.png "/>"); Factory.init (); }); /user name already exists function Checkusername () {//actual development replaced by: Ajax async:false var usErname = $ ("[Name=username]"). Val (); if (UserName = = "Admin1" | | | userName = = "Admin2") {return false;} return true; //Verify that the password is consistent function ConfirmPassword () {return $ (' [Name=password] '). val () = $ ([Name=password2]). Val ();} &nbs P </script> <style> td {Height:30px padding:5px;} </style> </head> <body> <h3> based on JQ Uery.validate Double verification </h3> <form method= "post" class= "form" id= "Form1" action= "/home/postregister" > < table> <tr> <td> name </td> <td> <input type= "text" name= "UserName" > </td> </ tr> <tr> <td> password </td> <td> <input type= "password" name= "password"/> </td> </tr> <tr> <td> Confirm password </td> <td> <input type= "password" name= "Password2"/& Gt </td> </tr> <tr> <td> sex </td> <td> <input type= "Radio" value= "1" name= "Sex"/> ; Male <input type= "Radio" value= "0"Name= "Sex"/> Women </td> </tr> <tr> <td> email </td> <td> <input type= "text" Name= " Email "/> </td> </tr> <tr> <td> mobile </td> <td> <input type=" text "Name=" mobi Le "/> </td> </tr> <tr> <td> qq </td> <td> <input type=" text "name=" QQ "/> &L t;/td> </tr> <tr> <td> education </td> <td> <p> <input type= "checkbox" Value= " 1 "name=" education "/> <input type=" checkbox "value=" 2 "name=" Education "/> Kindergarten <input type=" checkbox "Valu E= "3" name= "education"/> Primary </p> </td> </tr> </table> <button type= "Submit" > Submit submitted ( Ban browser JS for testing) </button> @Html. Raw (viewbag.validationbind) </form> </body> </html> |
Just a few lines of code is over. A registration
The effect is as follows:
CSS support is still good to be able to. Self beautification
2. Ajax notation
Change the Submit button and write an event to get it done.
Demo Download:
Http://xiazai.jb51.net/201506/other/sunkaixuan-ValidationSuarMVC-master.zip