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

爱⌒轻易说出口 提交于 2019-12-06 13:05:28

Look at this article: How To Validate Email Address With Regular Expression. The guy not only providing you with the regular expression, but also explaining step by step what it means. Not only its useful as an expression, but you can also learn a thing or two from this article.

Hope this helps. Please let me know if not.

[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

Did you check the ModelState property for validation errors? Look at the example at the bottom of this page:

http://blogs.msdn.com/b/youssefm/archive/2012/06/28/error-handling-in-asp-net-webapi.aspx

for a way of sending back error messages to the client when validation fails.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!