views:

101

answers:

2

Are there any modules that can help me compare phone numbers for equality?

For example, the following three numbers are equivalent (when dialling from the UK)

+44 (0)181 1234123
00441811234123
0181 1234123

Is there a perl module that can tell me this?

+3  A: 

The closest I can see on CPAN is Number::Phone which is an active project, and supports UK Phone numbers. It should work for the specific example you give. A few countries are supported.

If you've got phone numbers for other countries things could get more difficult due to local formatting idiosyncrasies.

martin clayton
This looks interesting, there could be similar numbers from different countries which would be a problem, wouldn't it?
imnotneo
You have (at least) two potential issues: context (see hobbs' answer) and format. Format depends on the locale in which the number is valid, again see hobbs' answer. There are some country specific modules in place already which you could use as a starting point.
martin clayton
+2  A: 

Supposing that the code you need doesn't exist, and you have to write it yourself, there are two basic operations that you need to do:

  1. Apply context. This is where you take the location of the dialing phone into account. If the call isn't international, you supply the country code; if the call isn't long-distance, you provide an area code, etc. This requires some rules per-locale, of course.

  2. Normalize. Remove meaningless spaces and punctuation, convert the international dialing prefix ("011" in NANPA, "00" in most of the rest of the world, but occasionally many weirder things) to the standard "+".

After completing those two steps properly, all inputs that are actually equivalent numbers should give identical output strings.

hobbs