E.164

E.164 is the international telephone numbering plan that ensures each device on the PSTN has globally unique number. This is what allows phone calls and text messages can be correctly routed to individual phones in different countries. E.164 numbers are formatted [+] [country code] [subscriber number including area code] and can have a maximum of fifteen digits.

Examples of E.164 Numbers

E.164 Format

Country Code

Country

Subscriber Number

+14155552671

1

US

4155552671

+442071838750

44

GB

2071838750

+551155256325

55

BR

1155256325

RegEx Matching for E.164

 There are several occasions when you'll want to programmatically verify that a string is in a valid E.164 phone number.  Some of these include: capturing a user’s phone number in a form, sending a Twilio SMS or voice call, and validating phone numbers in a database. According to the official ITU E.164 recommendation the format must be  number up to fifiteen digits in length starting with a ‘+’. You can also exclude 0 as the first character since there are no country codes that start with 0. Here is a sample regular expression: ^\+?[1-9]\d{1,14}$

However, this will also match numbers that are not valid phone number. A far more complex set of patterns would need to be specified to match only valid E.164 numbers for all countries around the world. A simpler and more robust option is to use the Twilio Lookup API to perform phone number validation and formatting without the need for RegEx