1

I want a regex-pattern for my phone number validator.

It has to allow digits, +, (, ) and -.

The restrictions are:

  • The + needs to be at the beginning of the output (something like: "+31(427)-103819" needs to be valid)
  • The +, (, ) and - are not required
  • The output has to end with a digit
  • No restrictions on length is required

Hope 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:

  • 190138190
  • 103-10381-390101
  • (0358)-103810381
  • (1038)1038103
  • +1081(1081)-193810
  • +1903(3913)193810
3

2 Answers 2

1

something very easy like this?

/^\+?[0-9-()]+$/
Sign up to request clarification or add additional context in comments.

1 Comment

Think this one is the easiest. And it covered all my possibilities. Thanks a lot!
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.