Free Thanksgiving & Christmas printables · Holiday Bundle: 3 kits for $15

How to Validate and Format Phone Numbers (E.164) the Right Way

By Wood Between Studio · · 2 min read

Phone numbers look simple until they aren't. People type (415) 555-2671, 4155552671, 001 415 555 2671 or +44 20 7946 0958. If you store whatever they typed, you can't text or compare them later. If you only count digits, you'll accept numbers that can never connect.

Store one canonical form: E.164

E.164 is the international form: + then the country code then the national number, with no spaces. +14155552671 and +442079460958 are E.164. Almost every SMS and voice API wants this.

Use a real parser, not a regex

A regex can check "this looks like a number." It can't tell a valid US number from a too-short one, or a French mobile from a UK landline. The library that does this well is Google's libphonenumber, the same one Android uses. It gives you:

  • valid or not (length and checksum for that country)
  • E.164, international and national forms
  • the country and calling code
  • a type when it can tell: mobile, landline, toll-free, VoIP, premium-rate

Pass a country hint for local numbers

4155552671 is incomplete on its own. With country=US it becomes +14155552671. If the user already typed +44…, you don't need the hint.

Don't look up the owner

A format check is not a "who is this?" lookup. Carrier, line-status and name lookups are a different kind of product, and they deal in personal data we don't collect or sell. For a signup form, format and type are enough: reject numbers that can't be valid, and store E.164 for the rest.

In one call

DialCheck wraps libphonenumber and is being listed on RapidAPI. It validates and formats, and it will not tell you who owns the line.

bash curl --request GET \ --url 'https://dialcheck-phone-number-validator.p.rapidapi.com/validate?phone=4155552671&country=US' \ --header 'X-RapidAPI-Key: YOUR_KEY' \ --header 'X-RapidAPI-Host: dialcheck-phone-number-validator.p.rapidapi.com'

The response includes e164, international, country and type. Docs: DialCheck documentation. There's a free monthly allowance.

If you also collect an email at signup, validate that too: how to validate email addresses at signup. Make room for what matters: store one clean number, not five shapes of the same one.

Pinterest image for this guide: Validate phone numbers. Store E.164. Accept local or +country. Check type, not just digits. Don't look up the owner. Use a country hint.
Save this guide for later. The image above is sized for Pinterest.

Get new free printables and sale alerts

Join the Wood Between Studio list for an occasional email when we add free printables, new designs or a sale. Unsubscribe anytime.

Subscribe free by email

Sign-up is handled by Gumroad, our shop platform. Make room for what matters.