Regex Email validation

后端 未结 30 1297
北海茫月
北海茫月 2020-11-22 12:16

I use this

@\"^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$\"

regexp to validate the email

([\\w\\.\\-]+) - this is f

30条回答
  •  眼角桃花
    2020-11-22 12:21

    Why not use EF6 attribute based e-mail validation?

    As you can see above, Regex validation for e-mail always has some hole in it. If you are using EF6 data annotations, you can easily achieve reliable and stronger e-mail validation with EmailAddress data annotation attribute available for that. I had to remove the regex validation I used before for e-mail when I got mobile device specific regex failure on e-mail input field. When the data annotation attribute used for e-mail validation, the issue on mobile was resolved.

    public class LoginViewModel
    {
        [EmailAddress(ErrorMessage = "The email format is not valid")]
        public string Email{ get; set; }
    

提交回复
热议问题