I changed my code to this after reading the hints here (I haven’t looked at the solutions yet and I’m trying to not look):
function telephoneCheck(str) {
let hasTenDigits = false;
let hasElevenDigits = false;
let startsWithOne = false;
let hasPermittedCharsOnly = false;
let hasCorrectParentheses = false;
const tenDigitRegex = /\d{10}/;
const elevenDigitRegex = /\d{11}/;
const startWithOneRegex = /^(1){1}/;
const permittedCharsRegex = /[0-9\-\(\) ]/;
const correctParenthesesRegex = /^\([0-9]{3}\)$/;
if (str.match(tenDigitRegex)) {
hasTenDigits = true;
}
if (str.match(elevenDigitRegex)) {
hasElevenDigits = true;
}
if (str.match(startWithOneRegex)) {
startsWithOne = true;
}
}
How do I check whether the last two Boolean values are true or not? Are my regular expressions for those alright? What about my regular expressions for the other three tests?