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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With