What Is E.164 Format?
最后更新 October 23, 2024

E.164 is an international standard that defines a phone number scheme that ensures each user worldwide has a unique phone number and allows them to connect to each other for phone calls and messages. As a result, the standard simplifies international calls and reduces the risk of dialing the wrong number.

According to the E.127 standard, there are different ways of specifying a phone number: geographical areas, global services, networks, etc. This article will use the standard representation for geographical areas, as this is the format used in the Vonage APIs.

The E.164 format

E.164 has a maximum of 15 digits and follows the format:

[country code] [national destination code] [subscriber number]

where:

  • Country Code (CC) corresponds with the international country calling codes (1 to 3 digits). By convention, international telephone numbers are represented by prefixing the country code with a plus sign (+).

  • National Destination Code (NDC) identifies a specific area, region or network within the country.

  • Subscriber Number (SN) is the individual phone number assigned to the user. The length of the NDC and the SN, must be 15 minus the length of the CC.

Examples


United States

The phone number 212 123 1234 can be represented using E.164 format as +12121231234, where:

  • +1 is the country code for the US.

  • 212 is the NDC.

  • 1231234 is the subscriber number.

United Kingdom

The phone number 020 1234 5678 can be represented using E.164 format as +442012345678, where:

  • +44 is the country code for the UK.

  • 20 is the area code for London.

  • 1231234 is the subscriber number.

Spain

The phone number 91 234 5678 can be represented in E.164 as +34912345678, where:

  • +34 is the country code for Spain.

  • 91 is the area code for Madrid.

  • 2345678 is the subscriber number.

Germany

The phone number 030 12345678 can be represented in E.164 as +493012345678, where:

  • +49 is the country code for Germany.

  • 30 is the area code for Berlin.

  • 12345678 is the subscriber number.

Why is E.164 important?

Many of our APIs use phone numbers following the E.164 standard. In particular, Network APIs expect API consumers to follow this format when calling some endpoints.

For example, according to the API reference, the /check endpoint receives the subscriber's phone number in E.164 format to verify whether a new link between their SIM and the phone number was recently established.

How can we validate an E.164 phone number?

As developers, it is essential to ensure the user's input is correct. This includes sanitizing, validating, and confirming that the phone number follows the E.164 format before making any API call. This will save us time and bandwidth.

One solution is to use one of the existing libraries to help validate phone numbers.

You might want to check the phone library if you are coding in JavaScript. The following example shows the validation of a phone number:

const {phone} = require('phone');

phone('+1(817) 569-8900', {country: '"USA'}); 

/* 
{  isValid: true, 
    phoneNumber: '+18175698900', 
    countryIso2: 'US', 
    countryIso3: 'USA', 
    countryCode: '+1'
}
/*

If you are a Python programmer, phonenumbers is your library. Here is an example:

import phonenumbers

my_number = phonenumbers.parse("+34911234567", "ES")
print(phonenumbers.is_valid_number(my_number)) # True

As an alternative, you could build your own validator using regular expressions. Depending on the regex language, something along the lines of:

^\+?[1-9]\d{1,14}$

The following Python uses that regular expression to validate some input data:

import re

def validate_e164(phone_number):
    pattern = r'^\+?[1-9]\d{1,14}$'
    return bool(re.match(pattern, phone_number))

# Test the function
test_numbers = [
    "+14155552671",      # Valid E.164 number (US)
    "+442071838750",     # Valid E.164 number (UK)
    "+493012345678",     # Valid E.164 number (Germany)
    "+34916543210",      # Valid E.164 number (Spain)
    "1234567890",        # Invalid (missing +)
    "+1234567890123456"  # Invalid (too long)
]

for number in test_numbers:
    print(f"{number}: {validate_e164(number)}")

Get in Touch!

How do you validate your users' input? Which library would you recommend using? We’d love to hear your feedback! Join us on the Vonage Community Slack or message us on X, and we will get back to you. 

Thanks for reading!

Alvaro NavarroSenior Developer Advocate

Alvaro is a developer advocate at Vonage, focusing on Network APIs. Passionate about Developer Experience, APIs, and Open Source. Outside work, you can often find him exploring comic shops, attending sci-fi and horror festivals or crafting stuff with those renowned tiny plastic building blocks.

Ready to start building?

Experience seamless connectivity, real-time messaging, and crystal-clear voice and video calls-all at your fingertips.

Subscribe to Our Developer Newsletter

Subscribe to our monthly newsletter to receive our latest updates on tutorials, releases, and events. No spam.