Phone numbers: lost in translation

We’re building a new line-of-business system for one of our customers, and need to migrate tens of thousands of contact records, along with address and phone-number information.

Phone numbers: lost in translation

The client has requested the system has validation for the phone numbers, and translates them into the international E.164 format.

The E.164 format shows what you need to dial to reach that phone from any other phone on the planet. All the different telco regulators specify how phone numbers must work within their respective jurisdictions, but E.164 is the overarching standard. If you write your number in that format, anyone will be able to call you, no matter where they’re phoning from.

To understand E.164, you have to understand the anatomy of a phone number. The basic subscriber number is the last part, and it can be anywhere from three to 11 digits long (sometimes longer). Before that comes the area code, which may or may not include a trunk prefix – that is, a digit or two that tells the phone system you’re dialling a number on a different exchange.

What comes first

In the UK, we use the trunk prefix 0, but we lie to ourselves by pretending this is part of the area code. It isn’t, as you’ll see when you format a UK phone number in the E.164 format – you drop the initial zero.

This misuse is a crime against international telephony

Before the area code is the country code – 44 for the UK, 61 for Australia, 353 for Ireland and so on. Virtually every country in the world has only one country code, but a few places have two or three, usually because they’re in the process of changing from one country code to another, or because their phone service is provided by two or more neighbouring countries.

Finally, at the beginning is the exit code, which is the number you need to dial to tell the exchange that you’re dialling an international number.

The exit code differs according to where in the world you’re calling from – it’s 00 in most of Europe, but 011 in the United States, for example – and E.164 specifies that you replace the exit code with a plus sign to cope with such variations.

Mobile phones actually let you enter a “+” as part of the number and will send it to the mobile service to which you’re connected to force it to dial the correct exit code.

So, if your UK number was 01234 123456, the correct way to write this in E.164 format is +44 1234 123456: the plus sign replaces the exit code; 44 is the country code for the UK; 1234 is the area code (minus the trunk prefix, 0); and 123456 is the subscriber number.

Note there are no brackets in an E.164 number, and you don’t put a zero in brackets between the country code and the area code. If you wrote it as +44 (0) 1234 123456, any call to that number would fail. Don’t do it; don’t let anyone you know do it; stop van drivers in the street and tell them the number on their van is wrong.

This misuse is a crime against international telephony, far worse than when you see London phone numbers written as 0207 123 4567 or (0207) 123 4567. The area code for London is 020: if you’re within the city, you need to dial eight digits to reach another London number, for example 7123 4567.

Similarly, Cardiff’s area code is 029, and all its subscriber numbers are 20XX XXXX. They should never be written as (02920) XXXXXX, but rather (029) 20XX XXXX or E.164 format +44 29 20XX XXXX. If you’re in Cardiff, you need to dial eight digits to get to another Cardiff number, which is why the 20 is part of the subscriber number, not the area code.

Validation

To get back to our original problem – how to validate the phone numbers – we need to know from where in the world a particular phone number hails. Luckily, all the information we’re supplied with for each contact contains a country, so we can extend the Countries table to include not only the ISO Country code (US, GB, FR, DE and so on) but also its dialling code (1, 44, 33, 49 and so on).

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.

Todays Highlights
How to See Google Search History
how to download photos from google photos