npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ke-msisdn-validator

v1.0.1

Published

Validate and format Kenyan phone numbers (MSISDN) and identify the telecom provider/operator (Safaricom, Airtel, Telkom, Faiba4g, Equitel). Fork of bnjunge/phone-formatter-ke with updated 2026 prefix data, plus M-PESA compatibility helpers.

Readme

ke-msisdn-validator

Fork notice: this package is a maintained fork of bnjunge/phone-formatter-ke (MIT). It inherits the original formatting logic but adds support for the current Kenyan numbering plan (the 01xx series that Safaricom now issues) and helpers built specifically for M-PESA compatibility checking.

Validate, format, and identify Kenyan phone numbers (MSISDN): normalize any input to E.164 254XXXXXXXXX, determine the telecom provider the number was originally allocated to (Safaricom, Airtel, Telkom, Faiba4g, Equitel), and check whether a number is compatible with Safaricom M-PESA — i.e. suitable for STK Push / Lipa Na M-PESA Online (Daraja).

Why this exists

The classic 07xx number range on Safaricom has been exhausted. Since 2020 Kenyan operators issue numbers in the 01xx family, and in August 2026 Safaricom added 0118, 0119, 0140–0143 and 0180–0182. Older libraries only know 07xx (and a couple of early 01xx blocks), so they reject valid Kenyan numbers. This fork keeps the prefix tables up to date.

Installation

npm install ke-msisdn-validator

Usage

const {
    FormatNumbers,
    checkOperator,
    isMpesaCompatible,
    isStkCompatible
} = require('ke-msisdn-validator');

// Normalize any format to 254XXXXXXXXX
FormatNumbers('0711123123');        // "254711123123"
FormatNumbers('+254 711 123 123');  // "254711123123"
FormatNumbers('0111123123');        // "254111123123"   (01xx works)

// Original-operator identification
checkOperator('254711123123');      // "Safaricom"
checkOperator('254110123123');      // "Safaricom"      (0110)
checkOperator('254140123123');      // "Safaricom"      (0140, Aug 2026)
checkOperator('254101123123');      // "Airtel"         (0101 is Airtel)

// M-PESA compatibility (latest prefixes included)
isMpesaCompatible('0118123123');    // true             (0118)
isMpesaCompatible('0140123123');    // true             (0140)
isMpesaCompatible('0182123123');    // true             (0182)
isMpesaCompatible('0700123123');    // true             (legacy 07xx)
isMpesaCompatible('5111123123');    // false

API

| Function | Description | | --- | --- | | FormatNumbers(phone) | Normalizes to a 12-digit 254XXXXXXXXX string, or "Invalid Phone Number ..." if the input is not a valid Kenyan number. | | checkOperator(phone) | Returns the operator a 254-formatted number was originally allocated to: "Safaricom", "Airtel", "Telkom", "Faiba4g", "Equitel", or "Invalid Operator". | | isMpesaCompatible(phone) | Boolean — true for any valid Kenyan mobile format (07x or 01x, normalized to 12 digits). Safe pre-check for M-PESA STK push. | | isStkCompatible(phone) | Alias of isMpesaCompatible. |

M-PESA / STK Push guidance (important)

This library is a fast client-side pre-check only. Two things matter for real payments:

  1. Number Portability (MNP). A prefix identifies the block where a number was originally allocated — not the network it is currently on. A 07xx/01xx number may have been ported to another operator. Treat isMpesaCompatible() as "this is a plausible M-PESA-capable number", not as a guarantee.
  2. Authoritative answer = Daraja. The Safaricom Daraja API (mpesaexpressrequest / STK Push) itself validates the MSISDN and returns a ResultCode. Always read the API response and use that as the final gate before treating a payment as initiated.

Because new 01xx ranges can be issued at any time, isMpesaCompatible() accepts any valid 07x/01x number rather than a closed list — so a new prefix is never wrongly rejected. The operator tables in checkOperator are updated as CA Kenya allocations are published.

Prefix data (updated August 2026)

| Operator | Ranges | | --- | --- | | Safaricom | 0700-0729, 0740-43, 0745-46, 0748, 0757, 0759, 0768-69, 0790-93, 0797-99, 0110-0119, 0140-0143, 0180-0182 | | Airtel | 0731-39, 0750-56, 0780-81, 0785-89, 0100-0103 | | Telkom | 0770-0776 | | Faiba4g | 0747 | | Equitel | 0763-0765 |

Tests

npm test

Support

If you find this package useful, you can support the developer by buying them a coffee:

License

MIT — fork of bnjunge/phone-formatter-ke which is also MIT. See LICENSE (original) for the upstream notice.