ASP. NET MVC common built-in validation features

Source: Internet
Author: User

1.[required]: Must be entered

" Please enter user name ")]  

2.[stringlength]: Limit string length

[Stringlength ( length cannot exceed 10 characters ")]  

3.[range]: Limit the range of values

[Range (0" age range between 0-120 years old ")]  

4.[regularexpression]: must conform to a regular expression (1) Use regularexpression directly to write expressions:

. [RegularExpression (@ "^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$"" Please enter   email format ").  Public Get Set

(2) Custom features:

 Public class Emailattribute:regularexpressionattribute   {  public      emailattribute ()          :base(@ " ^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$")      {      }  }  


Comparison of 5.Compare Judgments

 Public class Emailattribute:regularexpressionattribute  {      public  emailattribute ()           :base(@ "^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$")       {        }  }  


6.remote:ajax Remote Authentication, the return value is bool type TRUE indicates validation passed

// The    action method Controller    class request  method [Remote("User""Validate " " Post " " user name already exists " )]  publicstring Get set;   // ....    Public actionresult User ()  {  //..    if (true)    {      return Json (true, jsonrequestbehavior.allowget);    }     Else      return Json (false, jsonrequestbehavior.allowget);    }  

7.OutputCache Page Caching

[OutputCache (duration=)] // Set page Absolute cache  cache time is 20 seconds   public   actionresult Index ()  {      // Detail Code  }

Transferred from: http://www.cnblogs.com/iack/p/3500720.html

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.