Skip to content

Instantly share code, notes, and snippets.

@CEOehis
Created December 10, 2019 13:29
Show Gist options
  • Save CEOehis/4f005d6b6089a7599a2767446500570f to your computer and use it in GitHub Desktop.
Save CEOehis/4f005d6b6089a7599a2767446500570f to your computer and use it in GitHub Desktop.
function telephoneCheck(str) {
// Good luck!
const numberRegex = /^((\(\d{3}\)[ -]?)|(\d{3}[ -]?))\d{3}[ -]?\d{4}$/;
// check if it starts with 1
if(str.startsWith('1')) {
return numberRegex.test(
str.substring(1).trim()
);
}
return numberRegex.test(str);
}
telephoneCheck("555-555-5555");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment