The easiest way to match both
^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$
and
^[0-9]{3}-[0-9]{3}-[0-9]{4}$
is to use alternation ((...|...)): specify them as two mostly-separate options:
^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}$
By the way, when Americans put the area code in parentheses, we actually put a space after that; for example, I'd write (123) 123-1234, not (123)123-1234. So you might want to write:
^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$
(Though it's probably best to explicitly demonstrate the format that you expect phone numbers to be in.)
Answer from ruakh on Stack OverflowREGEX Tutorial to Validate US Phone Numbers
US Phone Number Validation - Help Needed
Regex for US phone number
help with regex validation for worldwide email, phone numbers and address
Videos
Hello, posting here in case someone can help. I need to add some sort of data validation in google forms for international phone numbers, the rules I have are:
The numbers should start with a plus sign ( + )
It should be followed by Country code and National number 1 to 4 digits between 0 and 9
It may contain white spaces or a hyphen ( – ).
the length of phone numbers may vary from 7 digits to 15 digits.
The form is going to be available to people that are based worldwide so it needs to be flexible enough to cover most countries. I've searched online extensively as this is quite common but my phone numbers keep getting errors, anyone has one that works? Thank you