Search code examples
javaregexphone-number

Regex - set max limit containing any char and numbers


I want to match strings with the following formats

  • 00355901234567
  • +355901234567
  • +*#355901234567
  • +355*#90123456
  • 44*#abc#9112345

and not match:

  • 0035590123456789
  • 44*#abc#91123456789
  • 44*#abc#911234567Abc

I just want to match any character in the beginning of the string and numbers in the end. the whole string should not exceed 15 characters.

So far, I've reached this regex:

^(.*)?\d{0,15}$

Although, the limit isn't working when I match any character with (.*).

Any thoughts?


Solution

  • How about something like

    ^.{0,14}\d$
    

    see the example : http://regex101.com/r/mK4dR9/3