Solving Telephone Number Validator Project

Tell us what’s happening:
I’m trying to do this JavaScript project and I need to complete 8 cases to pass the whole challenge. What are my mistakes on my code?


But when I read the hints I don’t understand . What is mean PermittedCharsOnly ?
MY code so far


function telephoneCheck(str) {
let hasTenDigits = false;
let hasElevenDigits = false;
let startsWithOne = false;
let hasPermittedCharsOnly = false;
let hasCorrectParentheses = false;
// regex
let hasTenDigitsRegex = /\d{10}/gmi;
hasTenDigits = hasTenDigitsRegex.test(str.replace(/\W/g, ''));

let hasElevenDigitsRegex = /\d{11}/gmi;
hasElevenDigits = hasElevenDigitsRegex.test(str.replace(/\W/g, ''));

let startsWithOneRegex = /^1[ ]?$/gmi;
startsWithOne = startsWithOneRegex.test(str); 

let hasCorrectParenthesesRegex = /[(][0-9]{3}[)]/gmi;
hasCorrectParentheses = hasCorrectParenthesesRegex.test(str);

if (!hasTenDigits && !hasElevenDigits) {
return false;
} else if (!hasCorrectParentheses) {
return false;
} else if (hasElevenDigits && !startsWithOne) {
return false;
} else {
return true;
}
}

console.log(telephoneCheck("555-555-5555"));


  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Telephone Number Validator

Link to the challenge:

well, if you look at the tests, there is this one:

telephoneCheck("123**&!!asdf#")

that check would be to reject this one because of the letters and random symbols. Allowed characters are numbers, spaces, dash and parenthesis

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.