user2102003
user2102003

Reputation: 11

ASP MVC MaxLength(value) attribute allows value 1 characters if applied for string

I was using [MaxLength(value)] for view model Email address field with [EmailAddress] attribute. And found that email's with value+1 characters path validation process.

Upvotes: 1

Views: 68

Answers (1)

Andrei
Andrei

Reputation: 44680

Try StringLength attribute for this purpose.

[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
public string Email{ get; set; }

Upvotes: 1

Related Questions