Skip to content

Instantly share code, notes, and snippets.

@secretorange
Created April 12, 2018 07:36
Show Gist options
  • Save secretorange/6f127998d5baafdf357cfdcf54a8b628 to your computer and use it in GitHub Desktop.
Save secretorange/6f127998d5baafdf357cfdcf54a8b628 to your computer and use it in GitHub Desktop.
Commonly used RegEx for DotNet. Email, Password etc.
public static class Constants
{
public static class RegEx
{
public const string Email = @"^[a-zA-Z0-9#'$%+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9#'$%+/=?^_`{|}~-]+)*[a-zA-Z0-9#'$%+/=?^_`{|}~-]*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9]{2,}$";
// Passwords must be at least 8 characters and contain at 3 of 4 of the following: upper case (A-Z), lower case (a-z), number (0-9) and special character (e.g. !@#$%^&*)
public const string Password = "^((?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])|(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z0-9])|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment