正在加载,请稍候…

Phone Number Formatting: Parse, Format, and Validate International Numbers

Parse and format international phone numbers. Learn about E.164 format, country codes, and validation.

International Phone Number Standards

Phone numbers vary enormously across countries in length, format, and routing. The E.164 standard (ITU-T recommendation) provides a universal format for international phone numbers used in telecommunications systems worldwide.

E.164 Format

The E.164 international phone number format:

+[country code][area code][subscriber number]

Requirements:

  • Starts with + (international prefix)
  • Maximum 15 digits total (excluding the +)
  • No spaces, dashes, or parentheses

Examples:

  • US number: +12125551234 (country code 1, area code 212)
  • UK number: +442071234567 (country code 44)
  • Japan: +81312345678 (country code 81)

E.164 is used by SMS gateways, VoIP systems, CRM platforms, and telephony APIs like Twilio.

National vs. International Format

The same number can appear very differently in national vs. international format:

Country National Format International (E.164)
USA (800) 555-0100 +18005550100
UK 020 7946 0958 +442079460958
Germany 030 12345678 +493012345678
France 01 23 45 67 89 +33123456789
Australia (02) 1234 5678 +61212345678
Japan 03-1234-5678 +81312345678

Note: National formats often omit the country code and use local area code notation with various separators.

Country Codes Reference

Common international dialing codes (country calling codes):

  • +1: USA, Canada, and Caribbean countries
  • +7: Russia and Kazakhstan
  • +20: Egypt
  • +27: South Africa
  • +33: France
  • +34: Spain
  • +44: United Kingdom
  • +49: Germany
  • +55: Brazil
  • +61: Australia
  • +81: Japan
  • +82: South Korea
  • +86: China
  • +91: India
  • +971: United Arab Emirates

Phone Number Validation

Validating phone numbers is more complex than it appears:

Basic Format Validation

// Simple regex for E.164 format
const e164Regex = /^\+[1-9]\d{1,14}$/;
e164Regex.test('+12125551234'); // true

libphonenumber

Google's libphonenumber library provides comprehensive validation using country-specific rules:

// Using libphonenumber-js
import { parsePhoneNumber } from 'libphonenumber-js';
const phone = parsePhoneNumber('+12125551234');
phone.isValid(); // true
phone.country; // 'US'
phone.formatInternational(); // '+1 212 555 1234'
phone.formatNational(); // '(212) 555-1234'

libphonenumber knows the valid number patterns for every country and validates not just format but whether the specific number could actually exist.

Phone Number Types

  • Geographic: Fixed-line numbers tied to a location
  • Mobile: Cell phone numbers
  • Toll-free: 800/888/877 in the US; free to call
  • Premium rate: Revenue-sharing numbers
  • VoIP: Internet-based phone numbers
  • Short code: 5-6 digit numbers for SMS services

The type affects validation rules and expected length.

Storing Phone Numbers in Databases

Best practices:

  1. Always store in E.164 format: Canonical, unambiguous, searchable
  2. Store as VARCHAR/TEXT: Not as integer (leading zeros, + sign)
  3. Store original input separately: If you need to display as entered
  4. Normalize on input: Validate and convert to E.164 at registration
-- Good: E.164 stored as text
CREATE TABLE contacts (
  id SERIAL PRIMARY KEY,
  phone_e164 VARCHAR(16),  -- +12125551234
  phone_display VARCHAR(30) -- (212) 555-1234
);

Using the Phone Parser and Formatter

Our tool:

  1. Parse any phone number format — handles parentheses, dashes, spaces, dots
  2. Detect country — identifies country from calling code
  3. Validate the number — checks against country-specific rules
  4. Convert formats — display in E.164, international, or national format
  5. Show number type — geographic, mobile, toll-free, etc.
  6. Batch processing — parse multiple numbers at once from a CSV

Use it for standardizing phone numbers before database import, validating user input, and reformatting contact lists.