If you’re using MVC and want to capture an email address, there is a great built-in way to validate the address. When creating your model, add the [EmailAddress] DataAnnotation like below.
[Required]
[EmailAddress]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 3)]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email Address")]
public string Email { get; set; }
Then you can add to your view:
<li> <%: Html.LabelFor(m => m.Email) %> <%: Html.TextBoxFor(m => m.Email) %> </li>
And if you enter an invalid email you’ll get the error:
