Regex Email validation

后端 未结 30 1173
北海茫月
北海茫月 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:35

    I've created a FormValidationUtils class to validate email:

    public static class FormValidationUtils
    {
        const string ValidEmailAddressPattern = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";
    
        public static bool IsEmailValid(string email)
        {
            var regex = new Regex(ValidEmailAddressPattern, RegexOptions.IgnoreCase);
            return regex.IsMatch(email);
        }
    }
    

提交回复
热议问题