Uses of Datatype.EmailAddress in asp/.net/mvc

前端 未结 4 1833
遇见更好的自我
遇见更好的自我 2020-12-16 22:39

I have a Account Model in which I am using Email Address as Username

public class RegisterModel
    {
        [Required]
        [Display(Name = \"Email Add         


        
4条回答
  •  北海茫月
    2020-12-16 23:25

    DataType alone will not trigger any server-side validation. But, since MVC 4 using DataType.EmailAddress will make the HTML input use type="email", which in turn makes jQuery Validation perform Regex validation on the client.

    .NET 4.5 introduced the [EmailAddress] attribute, a subclass of DataTypeAttribute. By using [EmailAddress] you get both client and server side validation.

提交回复
热议问题