Reputation: 18909
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.
Upvotes: 3
Views: 127
Reputation: 50328
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.
Upvotes: 3