Regex – ASP.NET MVC Web API data annotation regular expression for email

asp.net-web-apidata-annotationsregex

Using [RegularExpression(@"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$")] attribute never validates an email property of my model. I'm new to regular expressions so I can't figure out what is the problem. Little help?

Best Answer

[Required]
[Display(Name = "Email Address")]
[EmailAddress]
public string email { get; set; }

Something like this should solve you problem. The email validation has been build in 4.5 check out this msdn documentation