Validationsuar Form Validation Framework-support for ASP. NET MVC Webfrom

Source: Internet
Author: User
Tags button type

Strong under Validationsuar form verification Framework is useful:

1, support two-side verification of JavaScript and backend (front end is currently dependent on jquery.validate.js, can also be self-extended)

2. Simple code

3. Easy to call

4. Complete function

How to use:

Initializes a new initialization class, initializes all the classes that need to be validated, is fairly concise and can be managed uniformly, and your validation is completed in 70%.

Function Description:

Add default type (mail, phone, QQ, etc.)

Addregex validation in Add does not meet the situation of the use of

Addfunc using the JS function to verify (Note: JS function verification background needs to re-verify, so you can use the two methods to verify that the above, the majority of the sentence is used to verify that the user name is stored, two times the password can not be used in the case of a regular)

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", whether true/* is required */, "username"). Addregex ("[a-z,a-z].*", "username must start with a letter"). Addregex (". { 5,15} "," Length of 5-15 characters "). Addfunc ("Checkusername", "User name does not exist, input admin1 try"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Password", True, "password"). Addregex ("[0-9].*", "username must start with a number"). Addregex (". { 5,15} "," Length of 5-15 characters ").            Tooptionitem ()); Register Validationsugar.init (Pagekeys.register_key, Validationsugar.createoptionitem (). Set ("UserName", True, "user name"). Addregex ("[a-z,a-z].*", "username must start with a letter"). Addregex (". { 5,15} "," Length of 5-15 characters "). Addfunc ("Checkusername", "User name already exists!"). Tooptionitem (), Validationsugar.createoptioniTEM (). Set ("Password", True, "password"). Addregex (". { 5,15} "," Length of 5-15 characters "). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Password2", True, "password"). Addregex (". { 5,15} "," Length of 5-15 characters "). Addfunc ("ConfirmPassword", "password Inconsistent"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Sex", True, "gender"). Addregex ("0|1", "value is incorrect"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Email", True, "Mailbox"). ADD (ValidationSugar.OptionItemType.Mail, "Mailbox format is incorrect"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("mobile", false, "phone"). ADD (ValidationSugar.OptionItemType.Mobile, "phone format is incorrect"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("QQ", False, "QQ"). Addregex (@ "\d{4,15}", "QQ number format is incorrect"). Tooptionitem (), Validationsugar.createoptionitem (). Set ("Education", True, "education", True/*checkbox Multi-select mode */). Addregex (@ "\d{1,15}", "Value is incorrect").        Tooptionitem ()); }    }}

  

Global.cs Register, we can use it.

Verification in most cases in two kinds of 1, submit submission 2, JS Ajax submission

I. Wording of submission

Register a line of code to get the binding information to ViewBag

Postregister is also a line to complete the background verification

View

1. Quote JS and write the initialization function.

2, put @html.raw (Viewbag.validationbind) on the bottom of the page

@{viewbag.title = "Register"; Layout = null;} 

Complete

Form Ugly point, full-featured, based on the validate.js CSS support is good can. Self-beautification

II. Ajax notation

change the submit to a button, and the rest will be the same. A little bit more code

Demo Download:

Http://git.oschina.net/sunkaixuan/ValidationSuarMVC

Validationsuar Form Validation Framework-support for ASP. NET MVC Webfrom

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.