brian4
July 15, 2021, 5:58pm
1
Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function telephoneCheck(str) {
if (str.indexOf("(") === -1 && str.indexOf(")") > -1){
return false
}
if (str.indexOf(")") - str.indexOf("(") >= 5){
return false;
}
if (str[0] === "-") return false;
let polishedString = str.replace(/\-| /g , "");
console.log(polishedString)
if (polishedString.indexOf("(") < polishedString.indexOf(")")) {
polishedString = polishedString.replace(/\(|\)/g, "")
console.log(polishedString)
}
console.log(polishedString)
if (polishedString.length === 10) {
return true;
}else if (polishedString.length === 11 && polishedString[0] === "1") {
return true;
}
return false;
}
console.log(telephoneCheck("55 55-55-555-5"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.227
Challenge: Telephone Number Validator
Link to the challenge:
ilenia
July 15, 2021, 6:32pm
2
brian4:
"55 55-55-555-5"
it does not have the 3-3-4 pattern of a valid number format
brian4
July 15, 2021, 5:32pm
3
Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function telephoneCheck(str) {
if (str.indexOf("(") === -1 && str.indexOf(")") > -1){
return false
}
if (str.indexOf(")") - str.indexOf("(") >= 5){
return false;
}
if (str[0] === "-") return false;
let polishedString = str.replace(/\-| /g , "");
//console.log(polishedString.length)
if (polishedString.indexOf("(") < polishedString.indexOf(")")) {
polishedString = polishedString.replace(/\(|\)/g, "")
console.log(polishedString)
}
console.log(polishedString.length)
if (polishedString.length === 10) {
return true;
}else if (polishedString.length === 11 && polishedString[0] === "1") {
return true;
}
return false;
}
console.log(telephoneCheck("55 55-55-555-5"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.227
Challenge: Telephone Number Validator
Link to the challenge:
brian4
July 15, 2021, 6:35pm
4
So how can I add that condition in code.
ilenia
July 15, 2021, 6:38pm
5
I think you need to think a bit more on how to verify a number
the lines I quoted is where you evaluate the dashes and then eliminate them, but you are checking only for the presence at the beginning
system
Closed
January 14, 2022, 6:38am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.