Validate US phone number

Hi Everyone,

I have moved ahead a little and are attempting the advance algorithm scripting challenges. Most if not all the algorithms are difficult and find myself wanting to stop and not do this anymore, but I have this burning desire to finish not only this, but the entire full stack path. I have copied other peoples work to see if I can reproduce the work and some I see what has been done and can wrap my head around it and move on.

I’m not sure if we are allowed to post answers here so I won’t, but I just found two ways to answer “validate a us number”. I’m a little confused so I will work through

When I looked at the problem my first thought was a simple if statement, maybe simple is the wrong word. My question could a if statement be a possible solution? I not looking for the answer more whether or not it is possible, I want to try and get to the solution myself.

Any feedback is appreciated.

I think a tree of nested if statements and for loops would work, but it would get messy. RegEx was cleaner, but of course you’ve got to figure out how to do some complex stuff in RegEx. But I think it’s worth it since RegEx is such a vuluable tool once you figure it out.

The link I posted is that a good place to start?

Looks like a good place to start. I may check it out myself. There’re still a lot of RegEx secrets for me to unlock myself.