Skip to content

Instantly share code, notes, and snippets.

@kevinchisholm
Last active October 27, 2020 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinchisholm/459c17d7ca6f79b1bbb4ef7c00e53f1e to your computer and use it in GitHub Desktop.
Save kevinchisholm/459c17d7ca6f79b1bbb4ef7c00e53f1e to your computer and use it in GitHub Desktop.
function validatePhoneForE164(phoneNumber) {
const regEx = /^\+[1-9]\d{10,14}$/;
return regEx.test(phoneNumber);
};
validatePhoneForE164('+12125551212'); // true
validatePhoneForE164('12125551212'); // false
validatePhoneForE164('2125551212'); // false
validatePhoneForE164('+1-212-555-1212'); // false
validatePhoneForE164('+1 212 555 1212'); // false
validatePhoneForE164('+1 (212) 555-1212'); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment