Tell us what’s happening:
I’m trying to complete the telephone number validator challenge this is what I have so far
Your code so far
function telephoneCheck(str) {
var isValid = false;
//only allow numbers, dashes, dots parentheses, and spaces
if (/^[\d-\s.]+$/ig.test(str)) {
//replace all non-numbers with an empty string
var justNumbers = str.replace(/\D/g, '');
var count = justNumbers.length;
if(count === 10 || (count === 11 && justNumbers[0] === "1") ){
isValid = true;
}
}
console.log(isValid, str);
return isValid;
}
telephoneCheck("555-555-5555");
the tests
telephoneCheck("1 (555) 555-5555")
telephoneCheck("(555)555-5555") should return true.
telephoneCheck("1(555)555-5555") should return true.
aren’t passing though, what should I add? Thanks.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator