Skip to main content

Phone Number Formatting

AfriRoute requires all destination numbers in E.164 format: a leading +, the country code, and the national subscriber number with no spaces, dashes, or parentheses. Correct formatting is the single biggest factor in delivery success and avoids wasted credits on undeliverable numbers.

E.164 in One Line​

+[country code][national number]   β†’   +254712345678
ElementExampleRule
+ prefix+Always present, exactly once
Country code2541–3 digits, no leading zero
National number712345678National trunk prefix (0) removed

A common mistake is sending the national format with the leading zero (0712345678). When converting, drop the leading 0 and prepend the country code.

Country Code Reference​

CountryCodeExample Input (local)E.164 Output
πŸ‡³πŸ‡¬ Nigeria+2340801 234 5678+2348012345678
πŸ‡°πŸ‡ͺ Kenya+2540712 345 678+254712345678
πŸ‡ΏπŸ‡¦ South Africa+27082 123 4567+27821234567
πŸ‡ͺπŸ‡Ή Ethiopia+2510911 234 567+251911234567
πŸ‡¬πŸ‡­ Ghana+233024 123 4567+233241234567
πŸ‡ΉπŸ‡Ώ Tanzania+2550754 123 456+255754123456
πŸ‡ΊπŸ‡¬ Uganda+2560772 123 456+256772123456
πŸ‡·πŸ‡Ό Rwanda+2500788 123 456+250788123456

Validate and Normalize​

Always normalize numbers before sending. The example below strips formatting, removes the national trunk prefix, and prepends the country code:

import re

def to_e164(raw: str, country_code: str) -> str:
"""Normalize a local number to E.164. country_code without '+', e.g. '254'."""
digits = re.sub(r'\D', '', raw) # strip everything but digits
if digits.startswith('00'):
digits = digits[2:] # international 00 prefix
if digits.startswith(country_code):
return '+' + digits
digits = digits.lstrip('0') # drop national trunk zero
return '+' + country_code + digits

print(to_e164('0712 345 678', '254')) # +254712345678
print(to_e164('+234 801 234 5678', '234')) # +2348012345678
function toE164(raw, countryCode) {
let digits = raw.replace(/\D/g, '');
if (digits.startsWith('00')) digits = digits.slice(2);
if (digits.startsWith(countryCode)) return '+' + digits;
return '+' + countryCode + digits.replace(/^0+/, '');
}

toE164('0712 345 678', '254'); // +254712345678

Server-Side Validation​

You can have AfriRoute validate a number (and detect its carrier and line type) before sending:

curl -X POST https://api.afriroute.ai/api/v1/lookup/number \
-H "Authorization: Bearer $AFRIROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "number": "+254712345678" }'
{
"number": "+254712345678",
"valid": true,
"country": "KE",
"carrier": "Safaricom",
"line_type": "mobile",
"format": "E.164"
}

Common Errors​

Error codeCauseFix
INVALID_PHONEMissing + or country codeNormalize to E.164
UNSUPPORTED_COUNTRYNumber outside coverageCheck coverage
LANDLINE_NOT_SUPPORTEDFixed-line number for SMSUse a mobile number

Last Updated: May 2026