Skip to content

Instantly share code, notes, and snippets.

@turastory
Created July 14, 2022 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turastory/343b60f8fbae1a56dfbcb86c029c6f92 to your computer and use it in GitHub Desktop.
Save turastory/343b60f8fbae1a56dfbcb86c029c6f92 to your computer and use it in GitHub Desktop.
regular expressions for common inputs (email, special characters)
const emailRegex =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
const specialCharacterRegex = /[~`!@#$%\^&*\(\)_+\-=\[\]{};':"\\|,.<>\/?]/;
function isEmail(value: string) {
return emailRegex.test(value);
}
function isSpecialCharacter(value: string) {
return specialCharacterRegex.test(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment