-2

I have similar requirements to those mentioned in this question: compare two phone numbers

I want to compare phone numbers which are in different formats. For example, +467856753421 = 07856753421 = 7856753421.

Is it possible to do it without using the google library recommended in the linked question?

Tim
  • 5,435
  • 7
  • 42
  • 62
  • Is there a reason you want to avoid using the library recommended on the other question? Also, you've tagged this as regex - is there a reason that you want a regex solution? – Tim Jul 21 '20 at 10:18

2 Answers2

2

You could try to write a method that sanitises the input string to a standard format, and compare them, but phone numbers have so many different formats that something is bound to slip through the gaps, this is an area where I would strongly recommend a well-tested library that someone else has spent all that time writing for you.

Luke Storry
  • 6,032
  • 1
  • 9
  • 22
0

Try this regex:

(^[+]\d{2}|^0*|^00\d\d)(\d*)

The first capture group is your prefix. The second is your number. (This might need some adjustment if you have US prefixes which are +1 and 001.)

Tim
  • 5,435
  • 7
  • 42
  • 62
tomanizer
  • 851
  • 6
  • 16