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
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.
----------------------------------------------------------------------------