Free Numbers Pricing Reviews Feedback Terms & Policy API Docs Blog About
Log in Get Started
1 views 2 min read
Back to Blog
Developers

International Phone Number Validation: E.164, Country Codes and Pitfalls

International Phone Number Validation: E.164, Country Codes and Pitfalls

If your site serves several countries, phone number handling is where verification quietly breaks. People type spaces, zeros and brackets, and every country writes numbers differently. A single standard format fixes most of it.

The standard format

E.164 writes a number as a plus sign, the country code and the national number, with no spaces or other characters and a maximum length of fifteen digits. Store this form in your database, and show the nicer local format only on screen.

Typical input problems

User typesProblemFix
0300 1234567Leading national zeroRemove the zero when you add the country code
+92 300 123 4567SpacesStrip spaces and symbols
0092300...International prefixConvert 00 to +
300 1234567No country codeUse a country selector

Use a library

Phone numbering rules change often. Use a maintained validation library instead of your own regex, and update it. Regex alone cannot know which ranges are valid in a given country.

Select the country, then the number

  • A country dropdown with a default from the user's locale, not forced.
  • The dial code is shown next to the field.
  • Validation after the country is chosen.

Know what validation cannot tell you

A number can be valid in format and still not exist, not accept SMS or be a virtual line. Format checking is not proof of ownership. The OTP is the proof. See country codes explained.

Testing

Test several countries with real numbers or with rented virtual numbers from the country list.

Edge cases worth testing

  • Numbers with extensions.
  • Numbers from countries with variable length.
  • Pasted numbers with hidden characters.
  • Right-to-left languages in the form.

Storing and displaying

Save the E.164 value and the country in separate fields. Show the number in the local format when you display it, so that users trust what they see.

Questions people ask

Why store E.164?

One format makes searching, de-duplicating and sending consistent.

Is regex enough?

No. Use a maintained library.

Related guides and pages

Create a free OtpGet account and try it with a small balance.

Tags

#e164 phone format #phone number validation #international phone verification #libphonenumber #country code validation #phone input form
Contact us