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)
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using Syntacticsugar;
Namespace Validationsuarmvc.models {public class validates {public static void Init () {//login Validationsugar.init (Pagekeys.login_key, Validationsugar.createoptionitem (). Set ("UserName", "true/*" must be filled in, "User name"). Addregex ("[a-z,a-z].*", "User name must begin with a letter"). Addregex (". { 5,15} ", length 5-15 characters"). Addfunc ("Checkusername", "username does not exist, enter admin1 to try"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Password", True, "password"). Addregex ("[0-9].*", "User name must begin with number"). Addregex (". { 5,15} ", length 5-15 characters").
Tooptionitem ()); Register Validationsugar.init (Pagekeys.register_key, Validationsugar.createoptionitem (). Set ("UserName", True, "user name"). Addregex ("[a-z,a-z].*", "User name must begin with a letter"). Addregex (". { 5,15} ", length 5-15 characters"). Addfunc ("Checkusername", "Username already exists!"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Password", True, "password"). Addregex (". {5,15} ", length 5-15 characters"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Password2", True, "password"). Addregex (". { 5,15} ", length 5-15 characters"). Addfunc ("ConfirmPassword", "password Inconsistent"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Sex", True, "gender"). Addregex ("0|1", "incorrect value"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Email", True, "Mailbox"). ADD (ValidationSugar.OptionItemType.Mail, "mailbox format is not correct"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("mobile", false, "cell phone"). ADD (ValidationSugar.OptionItemType.Mobile, "phone format is not correct"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("QQ", False, "QQ"). Addregex (@ "\d{4,15}", "QQ number format is not correct"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Education", True, "education", True/*checkbox multiple selection mode * *). Addregex (@ "\d{1,15}", "Incorrect value").
Tooptionitem ());
}
}
}
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:
@{viewbag.title = "Register";
Layout = null; }
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