South Africa uses a clean, predictable numbering plan governed by ICASA (the Independent Communications Authority of South Africa). Every domestic number is exactly 10 digits in local form, always starting with 0. The country code is +27, so in international E.164 notation the leading zero is simply replaced by +27. What looks confusing at first — a dozen different 0XX codes for one country — follows a consistent rule once you know the prefix table.
This validator checks all three common input formats (local 0XX, E.164 +27XX, and the bare 27XX trunk without the plus), normalises to the canonical local form, verifies the total length, and then looks up the first three or four digits against the official ICASA prefix allocation table to identify the network or geographic region.
How it works
The algorithm has four steps:
-
Strip and normalise. Spaces, dashes, dots and parentheses are removed. Numbers starting with
+27or0027have the country code replaced with0to yield the 10-digit local form. Bare 9-digit strings (common when copy-pasting from international databases that dropped the leading zero) are also accepted by prepending0. -
Length check. The normalised string must be exactly 10 digits. South Africa has no 8-digit or 11-digit domestic numbers; any deviation indicates a mistype or a truncated paste.
-
Prefix lookup. The first three digits (
0XX) are matched against the ICASA allocation table. For the 080X and 086X shared-cost and toll-free sub-ranges, a four-digit prefix (0XXX) lookup provides a more specific label. If no match is found the number fails — unallocated prefixes like019,025,026or029do not exist in the South African numbering plan. -
E.164 and formatted output. On success the validator produces three ready-to-copy strings: the E.164 form (
+27XXXXXXXXX), the raw local form (0XXXXXXXXX) and the spaced human-readable form (+27 XX XXX XXXX).
Worked example
Suppose you have the string (082) 555-1234 from a web form. The
validator strips the parentheses and dash to get 0825551234, confirms it is
exactly 10 digits, matches the prefix 082 to Vodacom mobile, and outputs:
| Field | Value |
|---|---|
| E.164 | +27825551234 |
| Local | 0825551234 |
| Human-readable | +27 82 555 1234 |
| Network | Vodacom mobile |
| Type | mobile |
Now try +27 11 530 5000 (a Johannesburg landline). After stripping spaces
and converting the +27 prefix the local form is 0115305000. The prefix
011 resolves to Johannesburg / East Rand (geographic), confirming it is a
fixed-line number, not a mobile.
Finally, 0800 123 456 normalises to 0800123456. The four-digit prefix
0800 matches the toll-free sub-range, so the validator labels it
Toll-free (0800) — useful when you need to flag free-to-call numbers in a
CRM or dialler system.
Why prefix validation matters
Many international phone-number libraries skip South Africa’s internal
structure and accept any 10-digit string starting with 0. That lets through
numbers like 0191234567 or 0251234567 which have never been allocated and
will never connect. Prefix validation catches these silently invalid entries at
the point of data capture, before they pollute a database or trigger a wasted
API call to a carrier lookup service.