Validate and parse Egyptian national IDs, mobile numbers and governorates in PHP.
Framework-agnostic, with ready-made Laravel validation rules.
Every Egyptian product ends up writing the same regexes: is this a real national ID? is this a real mobile number? which governorate is code 21? This package does it once, properly — including Arabic-Indic digits (٠١٠...), every way people type +20, and the birth date, governorate and gender encoded in the national ID.
composer require predev-solutions/egypt-validatorsA national ID is 14 digits: C YYMMDD GG SSSS X — century, date of birth, governorate, serial (odd last digit = male) and a check digit.
use Predev\EgyptValidators\NationalId;
NationalId::isValid('29001010101234'); // true
$info = NationalId::parse('29001010101234');
$info->birthDate->format('Y-m-d'); // "1990-01-01"
$info->age(); // 36
$info->governorate->nameEn(); // "Cairo"
$info->governorate->nameAr(); // "القاهرة"
$info->gender; // Gender::Male
NationalId::parse('29002300101234'); // null — there is no 30 FebruaryRejects impossible dates, leap-year mistakes, unknown governorate codes and birth dates in the future.
use Predev\EgyptValidators\Mobile;
Mobile::isValid('+20 101 234 5678'); // true
Mobile::normalize('(+20) 10-1234-5678'); // "01012345678"
Mobile::normalize('٠١٠١٢٣٤٥٦٧٨'); // "01012345678"
Mobile::toE164('010 1234 5678'); // "+201012345678"
Mobile::carrier('01212345678'); // Carrier::OrangeAccepts 010…, +2010…, 002010…, 2010… and 10…, with spaces, dashes, dots and parentheses. Valid prefixes are 010 Vodafone, 011 e& (Etisalat), 012 Orange and 015 WE.
Numbers can be ported between networks, so treat
carrier()as a hint, not a guarantee.
use Predev\EgyptValidators\Governorate;
Governorate::from('21')->nameEn(); // "Giza"
Governorate::from('21')->nameAr(); // "الجيزة"
count(Governorate::governorates()); // 27Codes follow the national ID; 88 is used for people born abroad.
use Predev\EgyptValidators\Carrier;
use Predev\EgyptValidators\Gender;
use Predev\EgyptValidators\Laravel\EgyptianMobile;
use Predev\EgyptValidators\Laravel\EgyptianNationalId;
$request->validate([
'national_id' => ['required', new EgyptianNationalId()],
'phone' => ['required', new EgyptianMobile()],
// optional constraints
'driver_id' => ['required', EgyptianNationalId::make()->minAge(21)],
'nurse_id' => ['required', EgyptianNationalId::make()->gender(Gender::Female)],
'wallet' => ['required', EgyptianMobile::make()->carriers(Carrier::Vodafone)],
]);composer install
composer testIssues and pull requests are welcome — especially new Egyptian formats (landlines, tax registration numbers, commercial registry numbers).
MIT © predev. Solutions
Built by predev. Solutions — a Cairo software house building mobile apps, web platforms and brands for Egypt and the Gulf.