Yogesh Saroya
Yogesh Saroya

Reputation: 1495

regex for USA phone number format

I am using 1000hz for validation. for +1(999) 999-999 phone number I am using this regex in pattern

^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$

but its not working.

Upvotes: 0

Views: 275

Answers (1)

The fourth bird
The fourth bird

Reputation: 163207

You need to match a digit after matching the optional +

^[+]*\d[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s./0-9]*$

Regex demo

Or a bit more precise version::

^[+]?\d(?:\(\d{3}\)|[0-9]{3}) \d{3}-\d{3}$

Upvotes: 2

Related Questions