iraq-laravel / phone
Iraqi phone number validation, operator detection, and E.164 normalization for Laravel.
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0|^12.0
- illuminate/validation: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
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.