iraq-laravel/phone
Composer 安装命令:
composer require iraq-laravel/phone
包简介
Iraqi phone number validation, operator detection, and E.164 normalization for Laravel.
README 文档
README
Iraqi phone number validation, operator detection, and E.164 normalization for Laravel.
Features
- Validate Iraqi mobile and landline numbers
- Detect operator: Zain, Asiacell, Korek, Alkafeel Omnnea
- Normalize any input format to E.164 (
+9647XXXXXXXXX) - Detect all verified governorate landline area codes (Arabic + English + Kurdish Sorani)
- Laravel validation rule — object-based and shorthand string
- Restrict validation to specific operators
- Zero external dependencies — pure PHP
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
Installation
composer require iraq-laravel/phone
The service provider and facade register automatically. No manual setup needed.
Optionally publish the config and translation strings:
php artisan vendor:publish --tag=iraqi-phone
You can also publish just the config using the legacy tag:
php artisan vendor:publish --tag=iraqi-phone-config
The package includes translations for English, Arabic, and Kurdish (Sorani). After publishing, edit them under resources/lang/vendor/iraqi-phone/{locale}/validation.php.
Quick start
use IraqLaravel\Phone\Facades\IraqiPhone; $phone = IraqiPhone::parse('0780 123 4567'); $phone->local; // 07801234567 $phone->e164; // +9647801234567 $phone->formatted(); // 0780 123 4567 $phone->prefix(); // 0780 $phone->subscriberNumber(); // 1234567 $phone->operator; // Operator::Zain $phone->operator->name(); // Zain Iraq $phone->operator->label(); // زين العراق $phone->isMobile; // true
Accepted input formats
All of the following resolve to the same number:
07801234567
+9647801234567
009647801234567
9647801234567
0780 123 4567
0780-123-4567
Mobile operators
| Operator | Prefixes | Arabic |
|---|---|---|
| Zain Iraq | 0780–0789, 0790–0799 | زين العراق |
| Asiacell | 0770–0779 | آسياسيل |
| Korek Telecom | 0750–0759 | كورك تيليكوم |
| Alkafeel Omnnea | 0760–0769 | الكفيل أمنية |
Note: Iraq has Mobile Number Portability (MNP). A prefix may not reflect the subscriber's current operator after porting.
Landline area codes
All verified codes from the Iraqi national numbering plan.
| Area code | City / Governorate | Arabic |
|---|---|---|
| 1 | Baghdad | بغداد |
| 21 | Tikrit / Saladin | تكريت / صلاح الدين |
| 23 | Kut / Wasit | الكوت / واسط |
| 24 | Ramadi / Anbar | الرمادي / الأنبار |
| 25 | Baquba / Diyala | بعقوبة / ديالى |
| 30 | Hillah / Babil | الحلة / بابل |
| 32 | Karbala | كربلاء |
| 33 | Najaf | النجف |
| 36 | Diwaniya / Al-Qadisiyyah | الديوانية / القادسية |
| 37 | Samawa / Al-Muthanna | السماوة / المثنى |
| 40 | Basra | البصرة |
| 42 | Nasiriya / Dhi Qar | الناصرية / ذي قار |
| 43 | Amara / Maysan | العمارة / ميسان |
| 50 | Kirkuk | كركوك |
| 53 | Sulaymaniyah | السليمانية |
| 60 | Mosul / Nineveh | الموصل / نينوى |
| 62 | Duhok | دهوك |
| 66 | Erbil | أربيل |
| 67 | Halabja | حلبجة |
Validation
Object-based rule (recommended)
use IraqLaravel\Phone\Rules\IraqiPhoneNumber; use IraqLaravel\Phone\Enums\Operator; // Any valid Iraqi number 'phone' => ['required', new IraqiPhoneNumber()] // Mobile only — rejects landlines 'phone' => ['required', new IraqiPhoneNumber(mobileOnly: true)] // Restrict to specific operators 'phone' => ['required', new IraqiPhoneNumber(operators: [Operator::Zain, Operator::Asiacell])]
Shorthand string rules
'phone' => 'required|iraqi_phone' // any valid Iraqi number 'phone' => 'required|iraqi_mobile' // mobile only
Inside a Form Request
use IraqLaravel\Phone\Rules\IraqiPhoneNumber; class RegisterRequest extends FormRequest { public function rules(): array { return [ 'name' => ['required', 'string'], 'phone' => ['required', new IraqiPhoneNumber(mobileOnly: true)], ]; } }
Landline parsing
$phone = IraqiPhone::parse('060123456'); // Mosul landline $phone->isMobile; // false $phone->areaName; // "Mosul / Nineveh" $phone->areaNameAr; // "الموصل / نينوى" $phone->areaNameKu; // 'مووسڵ / نەینەوا' (Kurdish Sorani) $phone->operator; // Operator::Unknown $phone->e164; // +96460123456
toArray() — for API responses
IraqiPhone::parse('07801234567')->toArray(); // [ // 'raw' => '07801234567', // 'local' => '07801234567', // 'e164' => '+9647801234567', // 'formatted' => '0780 123 4567', // 'prefix' => '0780', // 'subscriber' => '1234567', // 'operator' => 'zain', // 'operator_name' => 'Zain Iraq', // 'operator_label' => 'زين العراق', // 'operator_label_localized' => 'Zain Iraq', // 'is_mobile' => true, // 'area_name' => null, // 'area_name_ar' => null, // 'area_name_ku' => null, // ]
Without the facade
use IraqLaravel\Phone\IraqiPhone; $service = new IraqiPhone(); $phone = $service->parse('07801234567');
Exception handling
parse() throws InvalidIraqiPhoneNumberException for unrecognized input. Use isValid() to check first:
use IraqLaravel\Phone\Exceptions\InvalidIraqiPhoneNumberException; if (IraqiPhone::isValid($input)) { $phone = IraqiPhone::parse($input); } // Or catch explicitly: try { $phone = IraqiPhone::parse($input); } catch (InvalidIraqiPhoneNumberException $e) { // handle error }
Running tests
composer install ./vendor/bin/phpunit
License
MIT — see LICENSE.
Author
iraq-laravel/phone 适用场景与选型建议
iraq-laravel/phone 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「phone」 「laravel」 「zain」 「iraq」 「asiacell」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iraq-laravel/phone 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iraq-laravel/phone 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iraq-laravel/phone 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Phone helper & validator for Nette Framework
Yii2 phone formatter and validator.
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
A Laravel validator for delimiter-separated list of emails.
A CakePHP behavior to validate foreign keys
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 47
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-19