Skip to content

Instantly share code, notes, and snippets.

@rickMcGavin
Last active December 18, 2016 02:06
Show Gist options
  • Save rickMcGavin/2a10e4732487bf52d2fe4895970bf5b9 to your computer and use it in GitHub Desktop.
Save rickMcGavin/2a10e4732487bf52d2fe4895970bf5b9 to your computer and use it in GitHub Desktop.
Challenge 1 of FreeCode Camp Advanced Algorithm Challenges
// freecodecamp
// advanced algorithm scripting
// validate us telephone numbers
function telephoneCheck(str) {
var regex = /^1?\s?((\(\d{3}\))|\d{3})(\s|\-)?\d{3}(\s|\-)?(\d{4})$/;
return regex.test(str);
}
console.log(telephoneCheck("555-555-5555")); //true
console.log(telehphoneCheck("1 555 555 5555")); //true
console.log(telehphoneCheck("1 555-555-5555")); //true
console.log(telehphoneCheck("1 (555) 555-5555")); //true
console.log(telehphoneCheck("(555)555-5555")); //true
console.log(telehphoneCheck("555)-555-5555")); //false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment