dignified
asked on
Parsing International Phone Numbers
I am trying to write a routine to parse international phone numbers, more specifically I want to extract the country code. I have a table of all the country codes, however, with variable numbering systems in Europe, I'm thinking it may be tough to do so reliably.
In calculating the country codes I hope they have arranged them so
that there is no way to overlap. For instance, if one country has
12345 (A) and another has 123 (B), then if I search for 123, I'll get
two hits, but only one is right. I can get around this by checking the
longest ones first
BUT
What happens if country B has a phone number like
123454545454545 where 123 is the country code and 454545454545 is the number
If I don't do it right, I could also accidentally get a hit on country A which has a country code of 12345.
I'm currently writing this routine in PHP. I'm not sure what section this would really go under.
In calculating the country codes I hope they have arranged them so
that there is no way to overlap. For instance, if one country has
12345 (A) and another has 123 (B), then if I search for 123, I'll get
two hits, but only one is right. I can get around this by checking the
longest ones first
BUT
What happens if country B has a phone number like
123454545454545 where 123 is the country code and 454545454545 is the number
If I don't do it right, I could also accidentally get a hit on country A which has a country code of 12345.
I'm currently writing this routine in PHP. I'm not sure what section this would really go under.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the code snippet above would return 3526 Luxemburg mobile, btw...
ASKER
It won't necessarily be the longest one though will it? Perhaps the system is worked out so that this is true? But with any random number this isn't the case.
The wikipedia entries for the phone numbering system contains all the information you need. You will have to do a few checks to make sure any given number fully fits a given format before you pull out the country code - this way you can be sure of getting it right.
Dial plan info,
http://en.wikipedia.org/wiki/Telephone_numbering_plan
Coutry code info
http://en.wikipedia.org/wiki/Country_calling_codes
Dial plan info,
http://en.wikipedia.org/wiki/Telephone_numbering_plan
Coutry code info
http://en.wikipedia.org/wiki/Country_calling_codes
>Perhaps the system is worked out so that this is true?
yes, the system is worked out that way, otherwise it could not work.
>But with any random number this isn't the case.
have you any proof of the contrary?
note: I work as billing engineer in a telco company, so I know what I am speaking about :)
yes, the system is worked out that way, otherwise it could not work.
>But with any random number this isn't the case.
have you any proof of the contrary?
note: I work as billing engineer in a telco company, so I know what I am speaking about :)
ASKER
>yes, the system is worked out that way, otherwise it could not work.
This is probably all I need to know.
>have you any proof of the contrary?
Didn't you just agree with me in your previous comment? Read my original question for an example of what I'm talking about. As long as all I have to do is use the longest match, then that is fine with me.
This is probably all I need to know.
>have you any proof of the contrary?
Didn't you just agree with me in your previous comment? Read my original question for an example of what I'm talking about. As long as all I have to do is use the longest match, then that is fine with me.
>As long as all I have to do is use the longest match, then that is fine with me.
you have to.
>>have you any proof of the contrary?
I am sure you could not have such a proof, but maybe you "found" an example where you had trouble identifying the correct code...
note: the example I showed for luxemburg 352 and 3526 can be differentiated in your tables, where you could say 352 = country code 3526 = country mobile subnet
then, depending on what you are looking for, you could exclude the subnets for example in your search, so you find the actual country and not the "deepest match" subnet...
you have to.
>>have you any proof of the contrary?
I am sure you could not have such a proof, but maybe you "found" an example where you had trouble identifying the correct code...
note: the example I showed for luxemburg 352 and 3526 can be differentiated in your tables, where you could say 352 = country code 3526 = country mobile subnet
then, depending on what you are looking for, you could exclude the subnets for example in your search, so you find the actual country and not the "deepest match" subnet...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>To really verify things you can then format check the rest of the number to be sure it has the right number >of digits for the numbering used in the country specified. This can also be a sanity check which can be >useful if the numbers have been entered manually and are likely to have mistakes.
Yes, the right number of digits is what I was also worried about since I don't have a table with this information.
Yes, the right number of digits is what I was also worried about since I don't have a table with this information.
Unfortunatly I don't know of a nice table of this information but you can get the full details for any given country's internal numbering system through the ITU website here,
http://www.itu.int/oth/T0202.aspx?parent=T0202
Here's an example of exchange information for Africa,
http://www.wtng.info/ccod-2.html#CC255
This is from the World Telephone Numbering guide,
http://www.wtng.info/
http://www.itu.int/oth/T0202.aspx?parent=T0202
Here's an example of exchange information for Africa,
http://www.wtng.info/ccod-2.html#CC255
This is from the World Telephone Numbering guide,
http://www.wtng.info/