hoang.tran/telco-utilities

PHP utilities for VN phone number processing

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/hoang.tran/telco-utilities

v1.0.1 2025-07-01 10:24 UTC

This package is not auto-updated.

Last update: 2025-12-30 13:41:05 UTC


README

A lightweight PHP library to sanitize, validate, mask, and detect carriers of Vietnamese phone numbers ๐Ÿ‡ป๐Ÿ‡ณ. Useful for backend validation, privacy masking, telco grouping, and data normalization.

โœ… Features

  • ๐Ÿ”’ Mask sensitive phone numbers (markPhone)
  • ๐Ÿงน Sanitize & normalize phone strings (sanitize)
  • ๐Ÿ“ฒ Detect mobile carrier (Viettel, MobiFone, etc.)
  • โœ… Validate if phone number is correct & valid
  • ๐Ÿ“Š Group phone numbers by carrier

๐Ÿ“ฆ Installation

Install via Composer:

composer require hoang.tran/telco-utilities

----------------------------------------------------------------------------

๐Ÿš€ Usage

use HoangTran\TelcoUtilities\PhoneHelper;

// Sanitize and normalize
$normalized = PhoneHelper::sanitize('+84 912 345 678');
// Output: 0912345678

// Validate
$isValid = PhoneHelper::isValidPhone('0968123456');
// Output: true

// Detect carrier
$carrier = PhoneHelper::detectCarrier('0968123456');
// Output: Viettel

// Mask phone number
$result = PhoneHelper::markPhone('0968123456');
// Output:
[
    'masked' => '096***3456',
    'raw'    => '0968123456',
    'valid'  => true,
    'carrier'=> 'Viettel',
    'error'  => null
]

// Group by carrier
$grouped = PhoneHelper::groupByCarrier([
    '0912345678',
    '0968123456',
    '0923456789',
]);
// Output:
[
    'Vinaphone'    => ['0912345678'],
    'Viettel'      => ['0968123456'],
    'Vietnamobile' => ['0923456789']
]

----------------------------------------------------------------------------

๐Ÿ›  API Reference
| Method                    | Description                                   |
| ------------------------- | --------------------------------------------- |
| `sanitize($phone)`        | Remove non-digits, normalize +84/84 โ†’ 0       |
| `isValidPhone($phone)`    | Validate if phone is a valid VN mobile number |
| `detectCarrier($phone)`   | Return carrier name (e.g. Viettel, Vinaphone) |
| `markPhone(...)`          | Mask sensitive parts of phone number          |
| `groupByCarrier($phones)` | Group array of phone numbers by telco         |

----------------------------------------------------------------------------

๐Ÿ“ Directory Structure
telco-utilities/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ PhoneHelper.php
โ”œโ”€โ”€ test.php
โ”œโ”€โ”€ composer.json
โ””โ”€โ”€ README.md

----------------------------------------------------------------------------

๐Ÿ“ License
MIT ยฉ Hoang Tran

----------------------------------------------------------------------------

๐Ÿ™‹โ€โ™‚๏ธ Contributing
Pull requests are welcome! Please open an issue first to discuss any major changes.

----------------------------------------------------------------------------