Phone Number Formatter
Format and validate phone numbers for different countries
About Phone Number Formatting
Phone number formatting is essential for creating user-friendly interfaces and ensuring data consistency across systems. Different countries have different phone number formats, lengths, and conventions. Proper phone number validation and formatting helps prevent errors, improves user experience, and ensures compatibility with telecommunications systems. The E.164 international standard defines the format for international phone numbers, allowing up to 15 digits.
E.164 International Standard
E.164 is the international telephone numbering plan that ensures each device has a globally unique number:
- Format: + [Country Code] [Subscriber Number]
- Maximum Length: 15 digits (including country code)
- Example: +1 555 123 4567 (US), +44 20 7123 4567 (UK)
- No Formatting: E.164 uses digits only, no spaces or punctuation
US Phone Number Format
United States phone numbers follow the North American Numbering Plan (NANP):
- Format: (NXX) NXX-XXXX where N is 2-9 and X is 0-9
- Length: 10 digits (or 11 with country code 1)
- Area Code: First 3 digits identify geographic region
- Exchange Code: Next 3 digits identify local exchange
- Subscriber Number: Last 4 digits identify individual line
- Examples: (555) 123-4567, +1 (555) 123-4567
UK Phone Number Format
United Kingdom phone numbers vary by type and region:
- Length: 10 or 11 digits (including area code)
- Country Code: +44
- London: 020 XXXX XXXX (11 digits total)
- Other Cities: 01XX XXX XXXX or 01XXX XXXXXX
- Mobile: 07XXX XXXXXX
- Examples: +44 20 7123 4567, +44 7123 456789
Common Phone Number Formats by Country
| Country | Code | Length | Example Format |
|---|---|---|---|
| United States | +1 | 10 | +1 (555) 123-4567 |
| United Kingdom | +44 | 10-11 | +44 20 7123 4567 |
| Canada | +1 | 10 | +1 (416) 555-0123 |
| Australia | +61 | 9 | +61 2 1234 5678 |
| Germany | +49 | 10-11 | +49 30 12345678 |
| France | +33 | 9 | +33 1 23 45 67 89 |
| Japan | +81 | 10 | +81 3 1234 5678 |
| China | +86 | 11 | +86 10 1234 5678 |
When to Use Phone Formatting
- User Registration: Format phone numbers for consistent storage
- Contact Forms: Display formatted phone numbers for better readability
- SMS Systems: Normalize phone numbers before sending messages
- CRM Systems: Standardize phone numbers in customer databases
- Call Centers: Format phone numbers for click-to-call functionality
- Data Import: Normalize phone numbers from various sources
Special Phone Numbers
Different countries reserve certain ranges for special services:
| Type | US/Canada | UK | Purpose |
|---|---|---|---|
| Emergency | 911 | 999, 112 | Police, Fire, Ambulance |
| Toll-Free | 800, 888, 877, 866 | 0800, 0808 | Free for caller |
| Premium Rate | 900 | 09XX | Paid services |
| Directory | 411 | 118XXX | Information services |
Mobile vs Landline Numbers
Some countries assign different prefixes to mobile and landline numbers:
- UK Mobile: Start with 07
- UK Landline: Start with 01 or 02
- US/Canada: No distinction by number (same format for both)
- France Mobile: Start with 06 or 07
- Germany Mobile: Start with 15, 16, or 17
Phone Number Validation Libraries
For production applications, consider using specialized libraries:
- libphonenumber: Google's comprehensive phone number library (Java, C++, JavaScript)
- phonenumbers (Python): Python port of libphonenumber
- Twilio Lookup API: Cloud-based phone number validation and lookup
- numverify: REST API for phone number validation
Common Formatting Conventions
- Parentheses: (555) 123-4567 - US style for area code
- Hyphens: 555-123-4567 - Simple separator
- Spaces: 555 123 4567 - European style
- Dots: 555.123.4567 - Alternative US style
- Plus sign: +1 555 123 4567 - International format
Test Phone Numbers
Many countries reserve specific ranges for testing:
| Country | Test Numbers |
|---|---|
| United States | (555) 0100 - (555) 0199 (reserved for fiction) |
| United Kingdom | +44 20 7946 0xxx (fictional use) |
| Germany | +49 30 0000 0000 (example numbers) |
Best Practices
- Store phone numbers in E.164 format (international standard)
- Display phone numbers in local format for user's country
- Always include country code for international compatibility
- Remove all formatting before validation or storage
- Accept multiple input formats but normalize to one storage format
- Provide clear input instructions and examples
- Use specialized libraries for complex validation needs
- Consider click-to-call links on mobile devices
Privacy and Security
- Phone numbers are personal data - handle according to privacy laws
- Implement consent mechanisms for SMS/call communications
- Provide easy opt-out options for phone-based communications
- Don't display full phone numbers publicly without consent
- Use rate limiting to prevent abuse of phone validation
- Consider two-factor authentication using phone numbers
Additional Resources
- ITU E.164 Standard: itu.int/rec/T-REC-E.164
- Google libphonenumber: github.com/google/libphonenumber
- Country Calling Codes: countrycode.org