Overview
ThePhoneNumberFormat enum defines the different formats in which phone numbers can be displayed. These constants are used with the PhoneNumberUtil::format() method to control the output format.
Format Types
E164
The E.164 format is the international standard for telephone number formatting. It produces a compact, machine-readable format with no spaces or formatting characters. Format:+[country code][national number]
- Example
- More Examples
- Storing phone numbers in databases
- API communication and data exchange
- SMS/telephony systems that require standardized format
- Any scenario requiring a canonical, unambiguous representation
E164 format is highly recommended for storage as it’s neutral, compact, and internationally recognized.
INTERNATIONAL
The INTERNATIONAL format is consistent with ITU-T Recommendation E.123 and provides a human-readable format with proper spacing for international use. Format:+[country code] [formatted national number]
- Example
- More Examples
- Displaying phone numbers to users in an international context
- Contact information on websites with global audiences
- Business cards and marketing materials for international use
- Email signatures for international companies
NATIONAL
The NATIONAL format displays the phone number as it would be dialed within its home country, including any necessary national prefix but without the country code. Format:[national prefix][formatted national number]
- Example
- More Examples
- Displaying phone numbers to users within the same country
- Local business listings and directories
- Forms and applications where the country context is known
- Print materials for domestic audiences
RFC3966
The RFC3966 format follows the RFC 3966 standard for representing telephone numbers as URIs. This format is designed for use in hyperlinks and web-based telephony applications. Format:tel:+[country code]-[formatted national number][;ext=[extension]]
- Example
- With Extension
- Creating clickable phone links in HTML (
<a href="tel:...">tags) - Mobile-friendly web applications
- QR codes containing phone numbers
- Any URI-based telephony application
Format Comparison
Here’s a side-by-side comparison of all formats for the same phone number:Quick Reference Table
| Format | Use Case | Example (Swiss) | Clickable | Storage |
|---|---|---|---|---|
| E164 | Storage, APIs | +41446681800 | No | ✅ Recommended |
| INTERNATIONAL | Display (global) | +41 44 668 1800 | No | Not recommended |
| NATIONAL | Display (local) | 044 668 1800 | No | ❌ Not recommended |
| RFC3966 | Web links, URIs | tel:+41-44-668-1800 | ✅ Yes | Not recommended |
Best Practices
For Storage: Always store phone numbers in E164 format in your database. This ensures consistency, simplifies searching, and makes international handling straightforward.
For Display: Choose the format based on your audience:
- INTERNATIONAL for multi-country applications
- NATIONAL when the user’s country matches the number’s country
- RFC3966 for clickable phone links
Example: Smart Formatting Based on Context
Related
- PhoneNumberUtil::format() - Format phone numbers using these constants
- AsYouTypeFormatter - Real-time formatting as users type
- PhoneNumberUtil - Main utility class for phone number operations