Telephone Validator help [SOLVED]

Telephone Validator help [SOLVED]
0.0 0

#1

Link to challenge

I’m using regexr.com to test my regex and I’m testing all the tests that should return true. However, for some reason it matches on the website, but when I run the tests on FCC, it doesn’t work. What’s wrong?

I know my code won’t pass every test, but I want to know why there’s a descrepancy between the site I’m using to check the regex and FCC’s tests.

function telephoneCheck(str) {
  // Check if valid pattern
  let pattern = /1?\s?(\(\d{3}\)|\d{3})[-\s]*\d{3}[-\s]*\d{4}/;
  if(str.match(pattern)){return true;}

  return false;
}

telephoneCheck("555-555-5555");

#2

Can you please share the FCC link for this challenge?


#3

Sorry. Edited first post.


#4

Which specific test case are you finding a discrepancy between the FCC site and regexr site?


#5

these four:

  • 1 555-555-5555
  • 1 (555) 555-5555
  • 1 555 555 5555
  • 1 456 789 4444

#6

For the above, your code returns true and the regexr site shows a match for it, so why do you think there is a discrepancy?


#7

Oh. I think it’s just my browser. I tried it on a different one and it worked. Thanks~