Possible Bug in Test: Validate US Telephone Numbers

Tell us what’s happening:
May have found a bug with one of the tests.

Using my regex expression:

^(?:(?:1?\s*(?:[-]\s*)?)?((\s*((\d{3})|\d{3})\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[-]\s*)?)([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[-]\s*)?([0-9]{4})$

on this site: https://www.regextester.com/17

The test: 5555555555

Was not passing. However, on fcc it passed the test no problem.

Your code so far

function telephoneCheck(str) {
 //NANP - http://en.wikipedia.org/wiki/North_American_Numbering_Plan
 
  //https://stackoverflow.com/questions/4338267/validate-phone-number-with-javascript
  
 //https://stackoverflow.com/questions/45620551/understanding-regexp-for-area-code-phone 
  
 //https://www.regextester.com/17 
  
  var regex1 = /^(?:(?:1?\s*(?:[-]\s*)?)?(\(\s*(\(\d{3}\)|\d{3})\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[-]\s*)?)([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[-]\s*)?([0-9]{4})$/; 
  
  
  console.log("str: " + str);
  console.log(regex1.test(str));
  return regex1.test(str);
}

console.clear();

telephoneCheck("555-six-5555");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/validate-us-telephone-numbers

regex differ a bit between implementations, furthermore i even saw stuff even withing the same language (javascript) that doesn’t work on codepen but works in the browser console, and your expression is rather complex

no idea what stuff that site uses to check the expression, but your regex works in my browser js console and works on repl.it too

1 Like