Created
April 20, 2022 14:21
-
-
Save afraz-khan/e1e2a1d3efe6cc25bf7d9e6ad8c95eff to your computer and use it in GitHub Desktop.
Phone Number Validation Regex Nodejs
This file contains hidden or 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
// E.164 Notation for Phone Numbers | |
const phonePattern = /^\+[0-9]{7,14}$/; | |
const phoneNumber = '+2312323231321'; | |
if (!phonePattern.test(phoneNumber)) { | |
const message = | |
"Phone number must start with '+' symbol, must have numerical digits only, " + | |
'min 7 digits and max 15 digits allowed'; | |
throw new Error(message); | |
} | |
return true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment