🔍Regex Recipes
Phone Number (E.164 International)
Validate international phone numbers in E.164 format (+country code without spaces).
Pattern
^\+[1-9]\d{1,14}$Explanation
E.164 format: + followed by 1-15 digits total (country code + number). No spaces or special characters.
Examples
US number
Input
+14155552671
Output
✓ Match
UK number
Input
+442071234567
Output
✓ Match
Serbia
Input
+381112345678
Output
✓ Match
Invalid - no plus
Input
14155552671
Output
✗ No match
Invalid - has spaces
Input
+1 415 555 2671
Output
✗ No match
Code Examples
JavaScript
const e164Regex = /^\+[1-9]\d{1,14}$/;
function validateE164(phone) {
return e164Regex.test(phone);
}
// Convert formatted to E.164
function toE164(phone, defaultCountry = '+1') {
// Remove all non-digits except leading +
let cleaned = phone.replace(/[^\d+]/g, '');
if (!cleaned.startsWith('+')) {
cleaned = defaultCountry + cleaned;
}
return cleaned;
}Try it Now
💡 Tips
- Use libphonenumber library for production
- Strip formatting before validation
- Store in E.164, display in local format
- Provide format examples to users
⚠️ Common Pitfalls
- E.164 is strict - no spaces, dashes, parentheses
- Users often enter formatted numbers
- Country code required (no local numbers)
- Maximum 15 digits total including country code