-1

Allow special characters before @ (i.e abc_@example.com).We are using the following regex:

class Program
{
    static bool IsValid(string value)
    {
        return Regex.IsMatch(value, "^(?(\")(\".+?\"@)|(([0-9a-zA-Z]((\\.(?!\\.))|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[0-9a-zA-Z])@))(?(\\[)(\\[(\\d{1,3}\\.){3}\\d{1,3}\\])|(([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,6}))$");
    }

    static void Main(string[] args)
    {
        Console.WriteLine(IsValid("example211_@hotmail.com"));
        Console.ReadLine();
    }
}
  • 1
    validating a email adress with regex is [complicated](https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression) I would search for other questions/answers instead of getting from one issue to another – fubo Jun 08 '18 at 11:10

1 Answers1

0

Use the following regex to full fill your requirement.

return Regex.IsMatch(value, @"^([a-zA-Z0-9_*!#%&$@\-\.]+)@((\[[0-9]{1,3}" +
              @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
              @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
Rakesh Kumar
  • 2,701
  • 9
  • 38
  • 66