-2

This seems simple but I've been struggling for hours now. The pattern is simple, a telephone number that optionally starts with a +, has 10-15 digits, and optionally has spaces, dashes or parentheses. The numbers and characters should be in no particular order.

I've tried using non-matching groups and seen so many different ways of validating phone numbers, but to no avail.

The best I have so far is ^\+?([0-9]{10-15}[)( -]*)$, but it only accepts the other characters if they're at the end of the pattern. This expression will be used in a Java context.

barnacle.m
  • 2,070
  • 3
  • 38
  • 82
  • 1
    Try this `^\+?(?:[ ()-]*\d){10,15)[ ()-]*$` –  Feb 22 '18 at 18:01
  • I will happily mark this as the correct answer if you post it, it seems to have done the trick. I don't know why the downvoting as this is not answered in the apparent "duplicate" question. – barnacle.m Feb 22 '18 at 19:53

1 Answers1

-1

Regular Expression

\+?([\s-]?[0-9]){10,15}+

as a Java string

"\\+?([\\s-]?[0-9]){10,15}+"
Tatarize
  • 10,238
  • 4
  • 58
  • 64