[asterisk-users] breaking DNID into country code, area code, and local code
Anselm Martin Hoffmeister
anselm at hoffmeister-online.de
Sun Mar 30 05:44:31 CDT 2008
Am Sonntag, den 30.03.2008, 16:56 +0800 schrieb mark morreny:
> Dear friends,
>
> I am wondering if there is any efficient way of extract the country
> code, area code, and local code into 3 different variables from one
> DNID that can look like 001630233-4333 or 0086213345333?
>
> International code can be 011, or 00.
> National code can be 0 or 1
> Country code can have 2 or 3 digits
> Area code can have 2 or 3 digits
> Local num can be 7-10 digits
>
> Is there anyway to break this down efficiently in the dialplan or AGI?
I think it can not be done efficiently, reliably, and for international
numbers.
The first problem would be to create the uniform international number in
+(X[XX])YYYY[YYYYYYYYYYY] format.
For example consider the number
01149228730
This might very well be a valid Sheffield, UK, number (no idea if it is,
and I will not call to find out :-) of area code 0114 and local
seven-digit number 9228730.
If dialled from US it will connect you to the University switchboard in
Bonn, Germany. (I had to find a really short number to fit the
seven-digit dialplan of Sheffield).
The problem is that some countries have "011" being (part of) a valid
area code, banning it as identification for "this is an international
number dialled from North America". Vice versa some countries seem to
have valid uses for "00" that mean different things than "international
dialling". I think it was used for "operator" in Spain back when they
had "07" for international dialling, and had been in some area codes in
Russia until they decided to migrate from 8~10 to 00 for international
dialling until 2010.
So getting your numbers standardized to + C[CC] A[AAAA] SSS[SSSSSS]
may already break on those problems.
Sorry, but you are not all happy either once you have that standardized
form. US is easy with the fixed +C AAA SSSSSSS form, and some countries
are similarly easy as they have fixed-length area codes (France, AFAIK)
or no area codes at all (Denmark). UK has two (London 20, Coventry 24
and a few others) up to four (afaik) area code digits, which possibly
can be recignized by logic, as +44 2 always is two-digit, and +44 1x1
and +44 11x are always three-digit - I do not know if that is valid
universally though. Any logic breaks when it comes to German area
codes, where +49 x0 may or may not be a valid area (30 - Berlin, but
5031 - Wunstorf, and 209 - Gelsenkirchen), and area codes range from
two to five digits, with a few three-digit subsribers nearly anywhere,
but up to nine digit subscriber numbers in Berlin.
For some countries information may even be hard to get - although you
probably will not receive many calls from Benin, Ethiopia or Mongolia,
and if you do indeed, you will have no trouble getting their local
telephone system explained.
Once you have your numbers standardized ($NUMBER in +xxxxxxx form) you
could of course query a database, looking for ${NUMBER:1:7} down to
${NUMBER:1:2}, such that if applicable the Country-/-Area can be
returned as string, as a fall back the country only, and if nothing
helps, the number can be discarded as "invalid" (assuming you have a
complete list of country prefixes).
I think you will not find anything much simpler that which can handle
the structure of phone numbers, as that is for historical and political
reason rather messy ;-)
BR
Anselm
More information about the asterisk-users
mailing list