Created
July 14, 2022 09:22
-
-
Save turastory/343b60f8fbae1a56dfbcb86c029c6f92 to your computer and use it in GitHub Desktop.
regular expressions for common inputs (email, special characters)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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