reusable / phone-checker
A reusable phone number validation package for Laravel.
Package info
github.com/tinmaunglynnwebdev-sudo/phone-checker-laravel
pkg:composer/reusable/phone-checker
This package is not auto-updated.
Last update: 2026-04-16 14:03:11 UTC
README
A sophisticated, highly configurable phone number validation and identification package for Laravel. Designed for precision, it handles sanitization, validation, and advanced metadata extraction like operator and country detection.
๐ Features
- Global Validation: Precision rules for Myanmar (MM), Thailand (TH), Japan (JP), United States (US), China (CN), Vietnam (VN), and United Kingdom (GB).
- Operator Detection: Specialized detection for Myanmar carriers (MPT, ATOM, U9/Ooredoo, Mytel).
- Country Identification: Automatically resolve the country from any given phone number.
- Smart Sanitization: Robustly handles common formatting characters (
-,,( )) before processing. - E.164 & Local Formats: Supports both international and national dialing formats.
- Pest Powered: Ships with a comprehensive Pest test suite.
๐ฆ Installation
Install the package via composer:
composer require reusable/phone-checker
The service provider will automatically register itself.
โ๏ธ Configuration
Publish the config file to customize default behavior and add new country rules:
php artisan vendor:publish --tag="phone-checker-config"
The configuration file allows you to:
- Change the default country.
- Add or modify country rules (regex, prefixes, lengths).
- Define operators with names and logos for any country.
๐ Usage
Basic Validation
The package provides a convenient PhoneChecker facade and is also available via dependency injection.
Via Facade
use Reusable\PhoneChecker\Facades\PhoneChecker; // Check if a number is valid for Myanmar PhoneChecker::check('09421234567', 'MM'); // true
Via Dependency Injection
use Reusable\PhoneChecker\PhoneChecker; public function store(Request $request, PhoneChecker $checker) { if ($checker->check($request->phone, 'MM')) { // ... } }
Laravel Validation Rule
The package includes a custom validation rule for seamless integration with Laravel's validation system.
use Reusable\PhoneChecker\Rules\Phone; $request->validate([ 'phone' => ['required', new Phone('MM')], ]);
Country Detection
Resolve the country of origin from a raw phone string.
// Detects country automatically $country = PhoneChecker::getCountry('+66 912 345 678'); // 'TH' $country = PhoneChecker::getCountry('+1-123-456-7890'); // 'US'
Operator Information (Myanmar Specialized)
Identify the carrier and retrieve operator metadata.
// Get operator key (e.g., 'MPT', 'ATOM', 'U9', 'Mytel') $operator = PhoneChecker::getOperator('09951234567'); // 'U9' // Get display-friendly operator name $operatorName = PhoneChecker::getOperatorName('09951234567'); // 'Ooredoo / U9' // Get operator logo URL $logo = PhoneChecker::getOperatorLogo('09951234567'); // 'https://.../u9-logo.png'
Country Metadata
Retrieve details about the detected or specified country.
// Get country flag (emoji) $flag = PhoneChecker::getFlag('MM'); // '๐ฒ๐ฒ' // Get full country name $name = PhoneChecker::getName('MM'); // 'Myanmar' // Get international dialing code $code = PhoneChecker::getCountryCode('MM'); // '+95'
Comprehensive Information
Get all available information about a phone number in a single call.
$info = PhoneChecker::getInfo('09421234567'); /* Returns: [ 'phone' => '09421234567', 'country' => 'Myanmar', 'iso' => 'MM', 'flag' => '๐ฒ๐ฒ', 'code' => '+95', 'operator' => 'MPT', 'logo' => 'https://...', 'is_valid' => true, ] */
๐งช Testing
The package is tested heavily using Pest. To run the tests, execute:
composer test
๐ License
The MIT License (MIT). Please see License File for more information.