Tell us what’s happening:
how may I separate in groups to filter them better? and How may I improve my filter to get the correct codes.
Your code so far
function telephoneCheck(str) {
let b=/\s+/gi;
let c=/\W+/gi;
let a=str.replace(b,"");
if(str[0]=="("||str[0]==1||str[0]==5){
let d=a.replace(c,"")
console.log(d)
if(d.length==10){
return true
}
}else{
return false
}
}
telephoneCheck("555-555-5555");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.
The easiest solution I can think of is just to match correct pattern from the start and until the end with regex. The way you’re trying to solve it would cause problems and be somewhat ugly. Try to refresh your regex skills and come back to the challenge later
I have only this left: telephoneCheck("(555-555-5555") should return false. What may I do? and How can I make to get a better code. I know this is hard code.