Reputation: 257
I want a regex-pattern for my phone number validator.
It has to allow digits, +
, (
, )
and -
.
The restrictions are:
+
needs to be at the beginning of the output (something like: "+31(427)-103819" needs to be valid)+
, (
, )
and -
are not requiredHope somebody can make me a regex for this, I have looked at different generators and ended up with something like this:
/^(\\+)*(\\d+)(\\()*(\\d+)(\\))*(-)*(\\d+)$/
This does not do what I want. Some example numbers that have to be valid:
Upvotes: 1
Views: 138
Reputation: 4743
Just pasted examples in http://gskinner.com/RegExr/, then searched existing ones in Community
(just double tap each item in the list until it fits for all examples).
Found this one:
^([().-\s0-9+]{2,}(?:(?::|x)[\s]*(?=(?:\d{1,4}))\d{1,4}[\s]*)?)$
Link: http://gskinner.com/RegExr/?353qd
I recommend you to use such tools when you wish to find a regex for suchpresumably popular patterns as a phone number or email address.
Upvotes: 1