Wednesday, November 20, 2013

How to implement minimum string length validation by Data annotation in ASP.NET MVC?

Two ways:
Fisrt:
        [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 10)]
 
Second:
Regular expression
[RegularExpression(@"^.{10,}$", ErrorMessage = "Minimum 10 characters required")]

No comments:

Post a Comment