Telephone Validator RegexIssue

To start off, I finished the challenge but I kind of had to cheat on one specific parameter because the Regex wasn’t working as expected. In the part where 5555555555 was supposed to return true, I used the following:

/\d{10}/g

This should look for a group of numbers that repeats exactly 10 times as far as I am aware but instead it was treating it as 10 or more times. I verified this because when I changed the number to 9 or less digits it would show false but on 10 or more digits it would always show true. The issue lied in that numbers like 258384841848 are not valid because they consist of too many digits. Am I not understanding this correctly? After about 30 minutes of research and trying I ultimately had to give in out of frustrations.

You can think of this in the following way - is it possible to find 10 digits in a number with more than 10 digits? Try thinking of a way to make regex check if there’s noting more in the string except of those 10 digits.

Unless I’m mistaken, isn’t that what a single number between curly braces is supposed to do? Check for an exact number of matches?

There’s no other constraints, just that regex has to match 10 digits. So if there’s more digits, it will match 10 digits from them.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.