In depth
The same number in 10 countries
These rows were produced by running the formatter on real example numbers. Notice how much the national format changes from country to country, while E.164 always has the same shape: a plus sign, the country calling code and the digits.
| Country | E.164 | International | National |
|---|---|---|---|
| United States | +12133734253 | +1 213 373 4253 | (213) 373-4253 |
| United Kingdom | +442079460958 | +44 20 7946 0958 | 020 7946 0958 |
| Germany | +4930123456 | +49 30 123456 | 030 123456 |
| France | +33123456789 | +33 1 23 45 67 89 | 01 23 45 67 89 |
| India | +919876543210 | +91 98765 43210 | 098765 43210 |
| Australia | +61212345678 | +61 2 1234 5678 | (02) 1234 5678 |
| Japan | +81312345678 | +81 3 1234 5678 | 03-1234-5678 |
| Brazil | +5511912345678 | +55 11 91234 5678 | (11) 91234-5678 |
| Spain | +34612345678 | +34 612 34 56 78 | 612 34 56 78 |
| Italy | +390612345678 | +39 06 1234 5678 | 06 1234 5678 |
Why international format has no brackets or hyphens
libphonenumber-js writes international numbers with spaces only, for example +44 20 7946 0958. Its documentation says this is a deliberate difference from Google's library, which sometimes uses hyphens and brackets. National format keeps each country's own style, which is why the US result above has brackets and a hyphen and the UK result starts with a 0.
Extensions are formatted per country
If a number has an extension, the library keeps it and uses the prefix people in that country expect. The US result uses " ext." and the UK result uses " x". In a tel: link the extension becomes a ;ext= parameter, which is how RFC 3966 defines it.
| Country | International format | tel: link |
|---|---|---|
| United States | +1 650 253 0000 ext. 123 | tel:+16502530000;ext=123 |
| United Kingdom | +44 20 7946 0958 x123 | tel:+442079460958;ext=123 |
Common formatting mistakes
Most bad phone data comes from a handful of habits.
- Storing the display format. Store E.164 and format on output, otherwise the same person appears as three different numbers.
- Formatting without a country. A number without a plus sign has no meaning until you say which country it is from, so choose the default country first.
- Keeping the (0) after the country code. People write +44 (0)20 7946 0958 in the UK. The library understands it: it returns +442079460958, with the 0 removed.
- Putting spaces in a tel: link. RFC 3966 does not allow spaces in the number, so use the E.164 form or the formatter's tel: column.