. NET MVC Model data validation

Source: Internet
Author: User

MVC provides very handy data validation, so you can generate relevant validation scripts in the foreground by simply adding the relevant regular in the model. You need to refer to two JS files:

Jquery.validate.min.js

Jquery.validate.unobtrusive.min.js

Model Data Validation Rollup:

[Display (Name ="Transfer Amount")] [Required (Allowemptystrings=false, errormessage ="Please enter the amount of the transfer")] [Range ( -,20000, errormessage ="The amount entered can only be between $100 to $20,000")] [RegularExpression (@"^[1-9]\d*$", errormessage ="The amount transferred must be an integer")]         Public decimalAmount {Get;Set; } /// <summary>        ///Transaction Password/// </summary>[Display (Name ="Transaction Password")] [Stringlength ( -, Minimumlength =6, errormessage ="{ 0} has a length of {2} to {1} characters")] [Required (Allowemptystrings=false, errormessage ="Please enter the transaction password")] [DataType (Datatype.password)] Public stringTradingpassword {Get;Set; } [Stringlength (Ten, Minimumlength =4, errormessage ="{0} must have a length greater than {2} characters and less than {1} characters")] [Display (Name="Password")]     Public Virtual stringLogpassword {Get;Set; } [Stringlength (Ten, errormessage ="{0} cannot have a length greater than {1} characters")] [Display (Name="name")]     Public Virtual stringRealname {Get;Set; } [Display (Name="Date of birth")]    //[Range (typeof (DateTime), "2011-12-31", "1950-1-1", errormessage = "{0} is scoped to {1} to {2}")]     Public VirtualDateTime Birthday {Get;Set; } [RegularExpression (@"\d{17}[\d| X]|\D{15}", errormessage ="the {0} is not in the correct format")] [Display (Name="ID Number")]     Public Virtual stringIdentityno {Get;Set; } [RegularExpression (@"[A-za-z0-9._%+-][email protected][a-za-z0-9.-]+\. [A-za-z] {2,4}", errormessage ="the {0} is not in the correct format")] [Display (Name="Email")]     Public Virtual stringEmail {Get;Set; } [Required (ErrorMessage="The registrant mailbox cannot be empty.")] [RegularExpression (@"^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$", errormessage ="The mailbox is not correct")]         Public stringEmail {Get;Set; }

Original address: http://www.cnblogs.com/jys509/p/4111034.html

. NET MVC Model data validation

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.