Skip to content

Instantly share code, notes, and snippets.

@maximgorbatyuk
Created February 17, 2021 03:00
Show Gist options
  • Save maximgorbatyuk/806b7b4afc25f72076f6da933648df43 to your computer and use it in GitHub Desktop.
Save maximgorbatyuk/806b7b4afc25f72076f6da933648df43 to your computer and use it in GitHub Desktop.
using System;
using System.Text.RegularExpressions;
namespace Utils.Helpers
{
public class EmailValidRegex : Regex
{
private const string Pattern =
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$";
public EmailValidRegex()
: base(
pattern: Pattern,
options: RegexOptions.Compiled | RegexOptions.IgnoreCase,
matchTimeout: TimeSpan.FromMilliseconds(250))
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment