How can I compare international phone numbers in Perl?

流过昼夜 提交于 2019-12-13 02:15:28

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2055988/how-can-i-compare-international-phone-numbers-in-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!