ZambiaMobileNetworks (ZambiaMobileNetworks v0.1.0)

Copy Markdown View Source

Identify Zambian mobile networks (Airtel, MTN, Zamtel, Zed Mobile) from a phone number.

The operator prefix is the two digits after the leading 0 or 260 country code.

NetworkLocalWith country code
Airtel097, 077, 05726097, 26077, 26057
MTN096, 076, 05626096, 26076, 26056
Zamtel095, 075, 05526095, 26075, 26055
Zed Mobile098, 078*, 058*26098, 26078*, 26058*

* 078/058 are reserved for Zed Mobile but not yet officially enabled by the network provider; they are detected pre-emptively.

Summary

Functions

Detects the network for an MSISDN, or nil if unrecognised.

Human-readable label for a network.

Returns the network logo as a base64 data: URI (200x200 PNG), or nil for an unknown network.

Returns the supported networks.

Operator prefixes for a network.

Whether the MSISDN belongs to the given network.

Types

network()

@type network() :: :airtel | :mtn | :zamtel | :zed

Functions

detect(msisdn)

@spec detect(String.t()) :: network() | nil

Detects the network for an MSISDN, or nil if unrecognised.

Accepts local (0XY…) and country-code (260XY…, +260 XY…) formats.

Examples

iex> ZambiaMobileNetworks.detect("0971234567")
:airtel

iex> ZambiaMobileNetworks.detect("260761234567")
:mtn

iex> ZambiaMobileNetworks.detect("+260 95 123 4567")
:zamtel

iex> ZambiaMobileNetworks.detect("0981234567")
:zed

iex> ZambiaMobileNetworks.detect("0911234567")
nil

label(atom)

@spec label(network()) :: String.t()

Human-readable label for a network.

logo(network, custom \\ nil)

@spec logo(network(), Path.t() | binary() | nil) :: String.t() | nil

Returns the network logo as a base64 data: URI (200x200 PNG), or nil for an unknown network.

Pass custom (a file path or raw image binary) to use your own logo instead of the bundled one. The custom image is returned encoded as-is — it is not resized.

iex> "data:image/png;base64," <> _ = ZambiaMobileNetworks.logo(:mtn)

networks()

@spec networks() :: [network()]

Returns the supported networks.

prefixes(network)

@spec prefixes(network()) :: [String.t()]

Operator prefixes for a network.

supports?(msisdn, network)

@spec supports?(String.t(), network()) :: boolean()

Whether the MSISDN belongs to the given network.

Examples

iex> ZambiaMobileNetworks.supports?("0961234567", :mtn)
true

iex> ZambiaMobileNetworks.supports?("0961234567", :airtel)
false