C# Regex for verifying e-mails

By | 2016.08.25

Regex for matching e-mail in C#. Came across http://emailregex.com/ which has a horrible example, so ended up making my own loosely based on that.

It leaves much to be desired, but will cover most use cases well enough.

public static readonly Regex _emailRegex = new Regex(
@"^[\w0-9!#$%&'*+/=?^_`{|}~-]{1,50}(?:\.[\w0-9!#$%&'*+/=?^_`{|}~-]{1,50}){0,8}"
+ @"@(?:[-\w0-9]{1,50}?\.){1,10}[-\w0-9]{2,50}?$",
RegexOptions.Compiled);

 

 

Leave a Reply