Email address validation using ASP.NET MVC data type attributes

来源:互联网 发布:实时监测网速软件 编辑:程序博客网 时间:2024/05/17 04:10

http://stackoverflow.com/questions/16712043/email-address-validation-using-asp-net-mvc-data-type-attributes

If you are using .NET Framework 4.5, the solution is to use EmailAddressAttribute which resides inside System.ComponentModel.DataAnnotations.

Your code should look similar to this:

    [Display(Name = "Email address")]    [Required(ErrorMessage = "The email address is required")]    [EmailAddress(ErrorMessage = "Invalid Email Address")]    public string Email { get; set; }

0 0