khakimjanovich/uz-phone

Framework-agnostic PHP library for strict Uzbek mobile phone parsing, normalization, validation, formatting, masking, and prefix metadata.

Maintainers

Package info

github.com/khakimjanovich/uz-phone

pkg:composer/khakimjanovich/uz-phone

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v1.2.0 2026-05-07 13:11 UTC

This package is auto-updated.

Last update: 2026-07-23 07:54:20 UTC


README

Latest Version PHP Version License Tests Tests

Strict Uzbek phone parsing for PHP. UzPhoneNumber wraps brick/phonenumber internally, adds Uzbekistan prefix data, and exposes a small Brick-style object API without leaking Brick classes.

use Khakimjanovich\UzPhone\Enum\Format;
use Khakimjanovich\UzPhone\UzPhoneNumber;

$phone_number = UzPhoneNumber::parse('(90) 123-45-67');

echo $phone_number;                         // +998901234567
echo $phone_number->format(Format::MASKED); // +998 90 *** ** 67

Why

Most apps only need one thing from Uzbek phone input: parse it into a canonical object, identify its prefix type, and then decide what their own domain should accept. uz-phone keeps that surface small, strict, and framework-agnostic.

  • Parses Uzbek phone numbers
  • Normalizes to E.164: +998901234567
  • Formats display output: +998 90 123 45 67
  • Masks private output: +998 90 *** ** 67
  • Returns prefix data with PHP backed enums
  • Uses brick/phonenumber for phone-number parsing and formatting
  • Keeps Uzbek prefix type and operator data in this package

Installation

composer require khakimjanovich/uz-phone

Requires PHP 8.2 or newer.

Usage

<?php

use Khakimjanovich\UzPhone\Enum\Format;
use Khakimjanovich\UzPhone\ParseException;
use Khakimjanovich\UzPhone\UzPhoneNumber;

try {
    $phone_number = UzPhoneNumber::parse('90 123 45 67');
} catch (ParseException $exception) {
    echo $exception->error_type->value;
}

$phone_number->getCountryCode();    // 998
$phone_number->getNationalNumber(); // 901234567
$phone_number->format(Format::E164);          // +998901234567
$phone_number->format(Format::INTERNATIONAL); // +998 90 123 45 67
$phone_number->format(Format::NATIONAL);      // 90 123 45 67
$phone_number->format(Format::MASKED);        // +998 90 *** ** 67

Prefix Data

<?php

use Khakimjanovich\UzPhone\Enum\Operator;
use Khakimjanovich\UzPhone\Enum\Prefix;
use Khakimjanovich\UzPhone\Enum\PrefixType;
use Khakimjanovich\UzPhone\Enum\Region;
use Khakimjanovich\UzPhone\UzPhoneNumber;

$phone_number = UzPhoneNumber::parse('+998901234567');

$phone_number->getPrefix() === Prefix::P90;                      // true
$phone_number->getOperator() === Operator::BEELINE_UNITEL;        // true
$phone_number->getPrefixType() === PrefixType::MOBILE_GSM;        // true
$phone_number->getOperator()?->value;                             // beeline_unitel
$phone_number->getOperator()?->label();                            // Beeline (Unitel)
$phone_number->getAllocationRegion() === Region::TASHKENT;        // true
$phone_number->getAllocationRegion()?->label();                    // Tashkent

Prefix data reflects original numbering allocation, not a guaranteed current operator or location after number portability. Geographic PSTN prefixes return null from getOperator() because the ITU table names the region, not a specific operator.

Supported Input

All accepted input normalizes to +998901234567.

+998901234567
998901234567
+998 90 123 45 67
901234567
90 123 45 67
(90) 123-45-67

The parser is intentionally strict. It accepts digits, a leading +, spaces, parentheses, and hyphens. It rejects unknown prefixes, wrong country codes, unsupported separators, letters, overlong numbers, and incomplete numbers.

Uzbek Prefixes

Source: ITU Uzbekistan numbering plan update.

Prefix Type Operator
20 MOBILE_GSM OQ_BEELINE
33 MOBILE_GSM HUMANS
36 FIXED_NETWORK_SERVICE_PROVIDER BUZTON
50 MOBILE_GSM UCELL_COSCOM
55 SIP UZTELECOM
61 GEOGRAPHIC_PSTN
62 GEOGRAPHIC_PSTN
65 GEOGRAPHIC_PSTN
66 GEOGRAPHIC_PSTN
67 GEOGRAPHIC_PSTN
69 GEOGRAPHIC_PSTN
70 GEOGRAPHIC_PSTN
71 GEOGRAPHIC_PSTN
72 GEOGRAPHIC_PSTN
73 GEOGRAPHIC_PSTN
74 GEOGRAPHIC_PSTN
75 GEOGRAPHIC_PSTN
76 GEOGRAPHIC_PSTN
77 MOBILE_GSM UZMOBILE_GSM
78 FIXED_NETWORK_SERVICE_PROVIDER
79 GEOGRAPHIC_PSTN
80 MOBILE_GSM PERFECTUM_MOBILE
87 MOBILE_GSM MOBIUZ_UMS
88 MOBILE_GSM MOBIUZ_UMS
90 MOBILE_GSM BEELINE_UNITEL
91 MOBILE_GSM BEELINE_UNITEL
92 MOBILE_GSM BEELINE_UNITEL
93 MOBILE_GSM UCELL_COSCOM
94 MOBILE_GSM UCELL_COSCOM
95 MOBILE_CDMA_GSM UZMOBILE_CDMA
97 MOBILE_GSM MOBIUZ_UMS
98 MOBILE_CDMA PERFECTUM_MOBILE
99 MOBILE_GSM

API

UzPhoneNumber::parse(string $phone_number): UzPhoneNumber

parse() throws ParseException when the input is not a valid Uzbek phone number. The exception exposes ParseErrorType through $exception->error_type.

UzPhoneNumber methods:

$phone_number->getCountryCode(): string
$phone_number->getNationalNumber(): string
$phone_number->getPrefix(): Prefix
$phone_number->getOperator(): ?Operator
$phone_number->getPrefixType(): PrefixType
$phone_number->getAllocationRegion(): ?Region
$phone_number->format(Format $format): string
$phone_number->isEqualTo(UzPhoneNumber $phone_number): bool

Parse error types:

ParseErrorType::EMPTY
ParseErrorType::INVALID_CHARACTERS
ParseErrorType::INVALID_COUNTRY_CODE
ParseErrorType::INVALID_LENGTH
ParseErrorType::UNKNOWN_PREFIX
ParseErrorType::UNHANDLED_BRICK_ERROR

Testing

composer test

License

MIT.