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
| Element | Example | Rule |
|---|---|---|
+ prefix | + | Always present, exactly once |
| Country code | 254 | 1β3 digits, no leading zero |
| National number | 712345678 | National 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β
| Country | Code | Example Input (local) | E.164 Output |
|---|---|---|---|
| π³π¬ Nigeria | +234 | 0801 234 5678 | +2348012345678 |
| π°πͺ Kenya | +254 | 0712 345 678 | +254712345678 |
| πΏπ¦ South Africa | +27 | 082 123 4567 | +27821234567 |
| πͺπΉ Ethiopia | +251 | 0911 234 567 | +251911234567 |
| π¬π Ghana | +233 | 024 123 4567 | +233241234567 |
| πΉπΏ Tanzania | +255 | 0754 123 456 | +255754123456 |
| πΊπ¬ Uganda | +256 | 0772 123 456 | +256772123456 |
| π·πΌ Rwanda | +250 | 0788 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 code | Cause | Fix |
|---|---|---|
INVALID_PHONE | Missing + or country code | Normalize to E.164 |
UNSUPPORTED_COUNTRY | Number outside coverage | Check coverage |
LANDLINE_NOT_SUPPORTED | Fixed-line number for SMS | Use a mobile number |
Relatedβ
Last Updated: May 2026