Hi @selimyay, I saw that the second two errors were involving a 1 followed by the brackets, which wasn’t included in your solution.
All that looked like it was missing was identifying if a 1 is there or not. So rewriting it, with this included, it would look something like this:
let phoneNumRegex = /^1?[-\s]?(\d{3}|\(\d{3}\))[-\s]?\d{3}[-\s]?\d{4}$/
Which really isn’t that different to your solution, it just moves it to the front, with the following:
The 1? matches an optional “1” character. The question mark makes the preceding “1” character optional. The [-\s]? matches an optional hyphen “-” or whitespace character “\s”. The square brackets define a character set that matches either “-” or “\s”, and the question mark makes it optional.
thank you so much for the answer, it worked. However, as I see, you added some extra \ and ( ) to the code. I guess ( ) is for (555) etc. but I don’t understand why you use extra \ ? for example here: \ (\d{3}|(\d{3}))
Hi, no problem! So the backslash is used to escape the brackets. So that the brackets aren’t evaluated as part of the regular expression, but instead are their actual characters.