Skip to content

Instantly share code, notes, and snippets.

@afraz-khan
Created April 20, 2022 14:21
Show Gist options
  • Save afraz-khan/e1e2a1d3efe6cc25bf7d9e6ad8c95eff to your computer and use it in GitHub Desktop.
Save afraz-khan/e1e2a1d3efe6cc25bf7d9e6ad8c95eff to your computer and use it in GitHub Desktop.
Phone Number Validation Regex Nodejs
// 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