Phone numbers: lost in translation
This way, we can check that the phone number starts with a plus and the appropriate dialling code for that country. We also need to know whether the country uses a trunk prefix that should be removed from the E.164 format. The most common trunk prefix is 0, but you’ll also find 1 (North America), 8 (Russia and its former republics) and 06 (Hungary).
Most countries that use a trunk prefix expect it to be removed if you’re dialling from outside the country, but there are exceptions, such as Italy, where the trunk prefix should be dialled as part of the area code both within and outside Italy.
Italians have to dial all the digits of their area code and subscriber number, but to confuse matters further, Italian mobile numbers start with a 3, not 03. So, although Italy officially has a trunk prefix of 0, its telephone numbering scheme works as if it didn’t.
This is effectively the same as the North American Numbering Plan (NANP), which covers the USA, Canada and many Caribbean islands. The trunk prefix for these countries is nominally 1, but this is also the country code – or the first part of the country code for the islands – so dialling a trunk call from one area to another requires you to dial the 1, even if the area is in a different country.
Italians have to dial all the digits of their area code and subscriber number, but to confuse matters further, Italian mobile numbers start with a 3, not 03
You only have to dial the exit code (011) if you’re dialling a number outside the NANP area. As such, dialling a number in the Bahamas, country code +1 242, from Jamaica, country code +1 876, requires you to dial 1 242 XXXXXXX, just as you would if you were dialling from Chicago to the Bahamas or New York to Baltimore. As far as E.164 formatting is concerned, there’s essentially no trunk prefix in NANP countries – the trunk is part of the country code.
Having investigated all cases of trunk prefixes in use today, I can only find three countries that have a trunk prefix but don’t want it to be removed for inward dialling from abroad: Italy, San Marino and Vatican City. All three are run by the Italian telephone regulator, and as far as E.164 formatting is concerned, work as though there were no trunk prefix.
To validate a phone number and transform it into E.164 format, we just need to know the country and follow a few simple rules:
– Remove all dashes and brackets from the number;
– If the number starts with “00” or “00”, remove these and substitute a plus sign;
– If it now doesn’t start with a plus sign and the correct dialling code for the country, add these elements;
– If it starts with a plus sign and the wrong country code, correct this code.
In any case, we let the user know we’ve changed the data and that they should check the changes are correct. If the country employs a trunk prefix and we find it immediately after the country code, we remove it.
The rest of the number we leave alone, since – short of making a trial phone call – there’s little more we can do to validate a phone number during data processing.
Following this procedure at least means the numbers are all shown in a consistent format, which makes it easier to spot mistakes visually, and also means unified messaging systems that let you click to dial phone numbers are more likely to work.
Also, if this information is synced to your mobile phone, you’ll be able to dial that number no matter where you are in the world.