mrone-inc/tz-phone-validator

Tanzanian phone number validator — identify Vodacom, Tigo, Airtel, Halotel, TTCL, and Zantel numbers

Maintainers

Package info

github.com/MrOne-inc/tz-phone-validator

pkg:composer/mrone-inc/tz-phone-validator

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-05-14 12:49 UTC

This package is auto-updated.

Last update: 2026-05-14 12:49:26 UTC


README

Validate and identify Tanzanian mobile phone numbers across all networks. Zero dependencies.

Supported Networks

Carrier Prefixes Example
Vodacom 074, 075, 076 0754 123 456
Tigo 065, 067, 071 0652 123 456
Airtel 068, 069, 078, 079 0684 123 456
Halotel 061, 062, 063 0622 123 456
TTCL 073 0732 123 456
Zantel 077 0772 123 456

Features

  • Validate — check if a number is a real Tanzanian mobile number
  • Identify carrier — detect which network a number belongs to
  • Normalize — clean any format to 255XXXXXXXXX
  • All formats accepted0754..., +255754..., 255754..., 754..., with spaces/dashes

Installation

PHP (Composer)

composer require mrone-inc/tz-phone-validator
use TzPhoneValidator\TzPhone;

TzPhone::isValid('0754123456');      // true
TzPhone::getCarrier('0754123456');   // "Vodacom"
TzPhone::normalize('0754123456');    // "255754123456"
TzPhone::isVodacom('0754123456');    // true

// Check all carriers
TzPhone::isTigo('0654123456');       // true
TzPhone::isAirtel('0684123456');     // true
TzPhone::isHalotel('0624123456');    // true
TzPhone::isTTCL('0734123456');      // true
TzPhone::isZantel('0774123456');     // true

Python (pip)

pip install tz-phone-validator
from tz_phone_validator import is_valid, get_carrier, normalize, TzPhone

# Functional API
is_valid("0754123456")      # True
get_carrier("0754123456")   # "Vodacom"
normalize("0754123456")     # "255754123456"

# OOP API
phone = TzPhone("0754123456")
phone.is_valid      # True
phone.carrier        # "Vodacom"
phone.normalized     # "255754123456"
phone.is_vodacom     # True

Node.js (npm)

npm install tz-phone-validator
const { isValid, getCarrier, normalize } = require('tz-phone-validator');

isValid('0754123456');      // true
getCarrier('0754123456');   // 'Vodacom'
normalize('0754123456');    // '255754123456'
isVodacom('0754123456');    // true

Java

Copy java/src/TzPhone.java into your project. Requires Java 17+.

TzPhone.isValid("0754123456");      // true
TzPhone.getCarrier("0754123456");   // Optional.of("Vodacom")
TzPhone.normalize("0754123456");    // Optional.of("255754123456")
TzPhone.isVodacom("0754123456");    // true

Input Formats

All functions accept any of these formats:

Input Normalized
0754123456 255754123456
+255754123456 255754123456
255754123456 255754123456
754123456 255754123456
0754 123 456 255754123456
0754-123-456 255754123456
(0754) 123456 255754123456

Running Tests

# PHP
cd php && composer install && vendor/bin/phpunit

# Python
cd python && pip install -e ".[dev]" && pytest

# Node
cd node && npm test

# Java
cd java && javac src/TzPhone.java tests/TzPhoneTest.java -d out && java -cp out TzPhoneTest

License

MIT