Tell us what’s happening:
Hello, so I was writing the code to this challenge. and i still had one number which had to return false, but returned true with me.
the number is: “6054756961”
I know I have tackled this problem in a very different way than others; however, my question is why is this number not valid. According to the main formats, shouldn’t this number be a valid number.
so my problem is not how to solve the challenge, but instead why this number in general is invalid. This supposedly will help me solve the last part of the challenge.
Your code so far
function telephoneCheck(str) {
let temp = str.split(' ').join('')
if (temp[0] == '-') {
return false
}
temp = temp.split('-').join('')
if (temp.match(/[(]/)) {
if (temp.match(/[)]/)) {
temp = temp.split('(').join('').split(')').join('')
} else {
return false
}
}
if (temp.match(/[)]/)) {
return false
}
if (temp.match(/\D/)) {
return false
}
if (temp.length == 10) {
return true
} else if (temp.length == 11) {
if (temp[0] != 1) {
return false
} else {
return true
}
}
return false
}
console.log(telephoneCheck("6054756961"));
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 7.0; T10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.12 Safari/537.36
.
Challenge: Telephone Number Validator
Link to the challenge: