What are the rules for validating a North American phone number? Also, is there a regex
I can use? Is there a gem to do this?
Here are few rules I have
Try this
(?:\+?|\b)[0-9]{10}\b
Explanation
@"
(?: # Match the regular expression below
# Match either the regular expression below (attempting the next alternative only if this one fails)
\+ # Match the character “+” literally
? # Between zero and one times, as many times as possible, giving back as needed (greedy)
| # Or match regular expression number 2 below (the entire group fails if this one fails to match)
\b # Assert position at a word boundary
)
[0-9] # Match a single character in the range between “0” and “9”
{10} # Exactly 10 times
\b # Assert position at a word boundary
"