Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less strict phone regex

I want to validate a phone number with regular expressions in JavaScript.

I found lot of expression that match a specific pattern, such as xxx-xxx-xxx, but I'm looking for a less strict expression, that matches only numbers, and optionally -, , and + without restricting the number to a specific schema.

like image 750
jviotti Avatar asked Jan 31 '26 11:01

jviotti


1 Answers

OK, so how about just:

/^[0-9\-,+]+$/

or, if you want to allow spaces too:

/^[0-9\-,+\s]+$/

You might also want to require that phone numbers have at least n digits, which you could do like this:

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

where you need to replace the n with the minimum number of digits you want.

like image 105
Ilmari Karonen Avatar answered Feb 02 '26 02:02

Ilmari Karonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!