Last active
December 18, 2016 02:06
-
-
Save rickMcGavin/2a10e4732487bf52d2fe4895970bf5b9 to your computer and use it in GitHub Desktop.
Challenge 1 of FreeCode Camp Advanced Algorithm Challenges
This file contains 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
// 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