开发者

How can I compare international phone numbers in Perl?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜