The E.164 phone number format is a plus sign, the country code and the national number with its leading 0 removed, with no spaces: for example 0712 345 678 in Kenya becomes +254712345678. Send every to number to the eSMS SMS API this way. The API tidies up spacing and some common mistakes for you, but it never guesses a missing country code, because a wrong guess sends the message to the wrong country.
Last reviewed: 29 October 2026
How to convert numbers to the E.164 phone number format
Find the country code
Every country has a calling code:
+254Kenya,+256Uganda,+255Tanzania,+250Rwanda,+260Zambia,+234Nigeria,+233Ghana,+237Cameroon,+27South Africa. The country pages in the docs list the code and the expected number of digits for each African country.Drop the leading 0 and add the code
Remove the trunk prefix 0 that people dial at home, then put
+and the country code in front:Written locally E.164 0712 345 678(Kenya)+2547123456780772 123 456(Uganda)+2567721234560803 123 4567(Nigeria)+2348031234567677 12 34 56(Cameroon, no trunk 0)+237677123456An E.164 number is at most 15 digits after the
+.Know what the API corrects for you
On single sends and Verify, the API accepts and normalises
+254712345678,254712345678(no plus),00254712345678, and numbers with spaces, dashes, dots or brackets. It also removes a stray 0 after the country code, so+2540712345678is read as+254712345678. What it will not do is add a country code to0712345678; that is refused withmissing_country_code, and the message suggests the international form for your account's country:{ "error": { "code": "missing_country_code", "message": "'0712345678' has no country code. Send numbers in international (E.164) format: country code + number without the leading 0, e.g. +237677123456. For Kenya that is +254712345678." } }Use a default country for local lists
If your data is full of local numbers, tell eSMS which country they belong to instead of converting them by hand. The personalised batch endpoint takes
"default_country": "UG"so0701234567is read as a Ugandan number. For imports and contacts in the dashboard, set DEFAULT COUNTRY under Settings > Messaging. Numbers that already have a country code always work.Validate before you send
POST /api/messages/validatechecks up to 1,000 numbers in one call, with no charge and no message sent. It returns the E.164 form, whether the number is valid, its country and its line type, so you can drop landlines and typos first:curl -X POST https://sms.esmsafrica.io/api/messages/validate \ -H "Authorization: Bearer $ESMS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"phone": ["+256772123456", "0712 345 678", "+2348031234567"]}'A single result looks like this (an array request also returns totals and a
resultslist):{ "input": "+256772123456", "e164": "+256772123456", "valid": true, "possible": true, "country": "UG", "type": "mobile", "national": "0772 123456", "reason": null }Validation is offline: it checks the format, the country and the number range, not whether the phone is switched on.
Common errors and how to fix them
| What you see | What it means | How to fix it |
|---|---|---|
400 missing_country_code | A local number with no country code, such as 0712345678. | Add the country code and drop the leading 0, or pass default_country on a batch. |
400 invalid_phone_length | The number has the wrong number of digits for its country. details includes expected_digits and got_digits. | Check for a missing or extra digit; the message includes an example number. |
400 invalid_phone | Not a phone number (letters, empty), an unknown country code, or digits outside every network range in that country. | Correct the number; run it through the validate endpoint to see why. |
| A Kenyan number reaches the wrong country | The number was stored without a country code and converted with the wrong one somewhere in your system. | Store E.164 with the country you collected, and never prepend a code blindly. |
rejected entries with landline in a batch | The number is a fixed line, which cannot receive SMS. | Remove it or ask the customer for a mobile number. |
Frequently asked questions
Do I have to include the plus sign?
It is recommended. The API also accepts the same digits without the plus, or with a 00 prefix, and normalises them to E.164.
Why won't the API add my country code automatically?
A local number such as 0712345678 can be valid in more than one country, so a guess could send your message to the wrong network. You state the country, in the number or as default_country on a batch, and the API never guesses.
What about numbers with spaces or dashes?
They are fine. Spaces, dashes, dots and brackets are removed before the number is checked.
Does validation tell me if a phone is on?
No. It checks the format, country and line type offline. Whether the phone received the message comes back in the delivery report.
Do the SDKs format numbers for me?
They pass the number through, and the API applies the rules above. Send E.164 from your code to be safe.
Related guides
Ready? Create a free eSMS account, then create a test API key and send your first simulated message in minutes. Nothing is charged until you switch to a live key.


