Support ASP.net MVC, webfrom form validation Framework Validationsuar Use Introduction _ Practical Tips

Source: Internet
Author: User

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

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.