0
return Regex.IsMatch(strIn,
    @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
    RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));

I'm using the above code to check for valid email id. But the above code is not allowing my email id with unicode characters. (For eg : Saànèéìòóù@gmail.com) But the above code is returning false for the mentioned email id. Can you guys please help me out in finding the correct regular expression.

Richard
  • 106,783
  • 21
  • 203
  • 265
Sachin jeev
  • 201
  • 4
  • 14
  • 1
    How about using [`\p{L}`](http://www.regular-expressions.info/unicode.html) for letters? e.g. `[\d\p{L}]` instead `[0-9a-z]` – bobble bubble Jun 14 '16 at 13:08
  • Sorry bobble. I'm quite new to regular expression . May I know where can I use it in above expression? – Sachin jeev Jun 14 '16 at 13:09
  • 3
    Emails cannot contain all Unicode characters, see: http://stackoverflow.com/questions/3844431/are-email-addresses-allowed-to-contain-non-alphanumeric-characters – Camilo Terevinto Jun 14 '16 at 13:10
  • Please review: http://stackoverflow.com/questions/7288271/email-regex-that-does-include-unicode-domains – Denn Jun 14 '16 at 13:10
  • 2
    Possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Dan Bechard Jun 14 '16 at 13:14
  • While asking how to search for Unicode characters using regular expressions would be a valid question, the question of using RegEx to identify valid email addresses has been beaten to death in the answer section of the question linked as duplicate above. – Dan Bechard Jun 14 '16 at 13:16

1 Answers1

2
return Regex.IsMatch(strIn,
    @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=(?:[0-9a-z]|[^\x20-\x7E]))@))" +
    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
    RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));

Use this regex.

parthi
  • 734
  • 1
  • 4
  • 13