Lorixen.
EN

Storing phone numbers in E.164 so SMS and calls work

Short answer: Store every phone number in E.164 format, a plus sign, the country code and the number with no spaces or leading trunk zero, such as +61412345678, and keep the customer's original input or a nicely formatted version only for display. Parse numbers at the point of entry with a library like Google's libphonenumber, using the customer's country as the default, and reject or query numbers that don't parse. That one decision fixes most failed SMS reminders, broken click-to-call links and duplicate customer records.

The mess that inconsistent numbers cause

Look at the phone column in most small business databases and you'll find the same mobile written several ways: 0412 345 678, 0412345678, +61 412 345 678, 61412345678, (04) 1234 5678. Each looks fine to a person. To software they're different strings, which leads to:

  • Failed texts. SMS providers generally expect numbers in international format; a local number with a leading zero may be rejected or sent to the wrong country.
  • Broken click-to-call. A tel: link with odd punctuation or a missing country code can fail on some phones, especially when the customer is abroad.
  • Duplicates. Search for a customer by phone and miss them because the stored version has spaces.
  • Bad matching. Caller ID, WhatsApp links and two-factor codes all need a consistent number.

What E.164 is

E.164 is the ITU's international numbering standard. Twilio's explanation of the format sums up the rules developers need: start with a +, follow with the country code and the national number, use digits only, and keep to a maximum of 15 digits. No country code starts with zero.

For Australia, that means a mobile written locally as 0412 345 678 becomes +61412345678: the country code 61, then the number without its leading zero. A Sydney landline like (02) 9876 5432 becomes +61298765432. The same idea applies everywhere, with each country's own code and trunk prefix rules.

Parse at entry, with a library

Don't write your own rules. Phone numbering plans are complicated, differ by country and change over time. Google's libphonenumber, a widely used Java, C++ and JavaScript library for parsing, formatting and validating international numbers, has ports for many other languages.

A typical flow when a customer types a number:

  1. Use a default region. If your customers are mostly in Australia, parse with Australia as the default so local numbers without +61 work.
  2. Let customers choose a country when they might be overseas, with a country selector next to the field.
  3. Parse and validate. If the library says the number isn't valid for that region, ask the customer to check it.
  4. Store the E.164 result. That's the value your app uses for texts, calls and lookups.
  5. Format for display using the library's national or international formatting, so customers see a familiar layout.

Do the parsing on the server as well as in the browser or app, so imports and admin screens produce the same result.

Help customers type it right

A good phone field makes correct entry easy:

  • Use type="tel" so phones show a number keypad.
  • Add autocomplete="tel" so browsers can fill the saved number.
  • Accept spaces, dashes and brackets; strip them during parsing rather than blocking them.
  • Show an example in the right format for the selected country.
  • Say why you need the number, such as "for delivery updates by text".

Avoid splitting the number across several boxes. It breaks autofill and paste.

Handle what doesn't fit

Not everything fits neatly:

  • Extensions. Office numbers sometimes need an extension. Store it in a separate field rather than appending text to the number.
  • Short codes and service numbers. Some special numbers aren't diallable internationally. If your app stores supplier numbers like these, store them separately or flag them.
  • Numbers you can't parse. Keep the raw input in a separate column, flag the record for review, and don't send messages to it until it's fixed.

Cleaning up existing data

For an existing database:

  1. Export the phone column with each customer's country, or assume your main country if you don't have one.
  2. Parse every number with the library and record the result, the original and whether it was valid.
  3. Review the invalid ones; many will be obvious, like a missing digit or a landline without an area code.
  4. Write the E.164 values to a new column and switch your app to use it.
  5. Merge duplicate customers that now share a number, after checking they really are the same person.

Keep the original values for a while in case a correction is needed.

Test the edge cases

Before going live, check:

  • A local mobile, a local landline and an overseas number.
  • A number pasted with spaces and a leading +.
  • A number with the country code typed but the trunk zero left in, like +61 0412…, which libraries usually handle but is worth confirming.
  • SMS and click-to-call with the stored value on a real phone.

A worked example

Take a hypothetical Melbourne physiotherapy clinic whose appointment reminders often failed to send. Its booking form accepted any text, and staff typed numbers several different ways. The clinic's developer parsed all existing numbers with libphonenumber using Australia as the default, fixed the few dozen that didn't parse, stored E.164 values, and changed the form to a tel field with a country selector and a display format. Reminder failures dropped to the occasional genuinely wrong number.

FAQ

Should I show customers the +61 format?

You don't have to. Store E.164, but display numbers in the familiar national format for local customers.

Does E.164 work for landlines?

Yes. Any public phone number has an E.164 form.

Can libphonenumber tell me if a number is a mobile?

It can often infer the line type from numbering ranges, but numbers can be ported, so treat it as a hint.

What about WhatsApp click-to-chat links?

They also use the international number, digits only, which you can derive from the E.164 value.

If your texts and calls fail because phone numbers are all over the place, ask us to clean them up.

Sources

WhatsAppBook a call