aroon/egyptian-national-id-checker
Composer 安装命令:
composer require aroon/egyptian-national-id-checker
包简介
A PHP package to parse and validate Egyptian National IDs, with Laravel support.
README 文档
README
A PHP and Laravel package to parse and validate Egyptian National IDs (14 digits).
Installation
You can install the package via Composer:
composer require aroon/egyptian-national-id-checker
(Note: Ensure you are requiring the local path in your project if you haven't published it to Packagist).
Features
- Sanitization: Automatically cleans input by converting Arabic/Hindi numerals (٠-٩) to English numerals and stripping spaces or dashes.
- Validation: Strict validation of the 14-digit format, century, birth date, governorate code, and check digit.
- Data extraction: Easily extract birth date, gender, governorate, and age.
Usage in PHP
use Aroon\EgyptianNationalId\EgyptianNationalId; // 1. Basic Parsing and Validation $id = new EgyptianNationalId('٢٩٠-٠١٠١ ١٢٣ ٤٥٦٧'); if ($id->isValid()) { $id->getBirthYear(); // 1990 $id->getGender(); // "female" $id->isAdult(); // true $id->getGovernorateName();// "Cairo" $data = $id->toArray(); }
🧠 Static Safe Helpers
Need a quick answer without crashing or handling invalid objects? Use the static safe helpers. They return false gracefully if the ID is malformed.
EgyptianNationalId::isValidId('29001011234567'); // true EgyptianNationalId::checkIsMale('29001011234567'); // false EgyptianNationalId::checkIsAdult('29001011234567');// true
🎲 ID Generator (For Testing/Factories)
Generate 100% mathematically correct National IDs matching precise criteria, great for Unit Tests:
// Generate a completely random valid ID $randomId = EgyptianNationalId::generate(); // Customize generation (e.g. Female, born in 1990, from Cairo) $specificId = EgyptianNationalId::generate([ 'gender' => 'female', 'year' => 1990, 'governorate' => '01' // Cairo ]);
🎛️ Data Engine (Collections and Big Data)
To analyze arrays or databases packed with thousands of IDs, use EgyptianNationalIdEngine:
use Aroon\EgyptianNationalId\EgyptianNationalIdEngine; $dataset = ['29001011234567', '30205051234567', 'invalid_id']; $engine = EgyptianNationalIdEngine::make($dataset); // 1. Filter out IDs easily $onlyMales = $engine->filter(fn($id) => $id->isMale()); // 2. Extract quick demographics & statistics $stats = $engine->stats(); /* { "total": 2, "males": 1, "females": 1, "adults": 2, "governorates": { "Cairo": 1, "Alexandria": 1 } } */ // 3. Merge parsed real-world analysis into your original arrays $users = [ ['name' => 'Ahmed', 'national_id' => '29001011234567'] ]; $analyzedUsers = $engine->mapWithAnalysis($users, 'national_id'); // Output will now contain an 'analysis' array attached to Ahmed's row with his birthday, gender, etc.
Usage in Laravel
The package automatically registers a ServiceProvider for Laravel. It provides a new validation rule called national_id, which you can use directly in your Form Requests or inline validation.
use Illuminate\Http\Request; public function store(Request $request) { $request->validate([ 'national_id_field' => ['required', 'string', 'national_id'], ]); // Or the string syntax // 'national_id_field' => 'required|string|national_id', // ... }
Or you can use the built-in Rule object:
use Aroon\EgyptianNationalId\Rules\NationalIdRule; public function store(Request $request) { $request->validate([ 'national_id_field' => ['required', new NationalIdRule()], ]); }
Testing
Run the included PHPUnit tests with:
composer test # or ./vendor/bin/phpunit
License
MIT License.
Note
This package is based on the algorithm and logic from mahmoudEbeid2/egyptian-national-id.
aroon/egyptian-national-id-checker 适用场景与选型建议
aroon/egyptian-national-id-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「validation」 「laravel」 「Egypt」 「national-id」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aroon/egyptian-national-id-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aroon/egyptian-national-id-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aroon/egyptian-national-id-checker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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
PHP Validator for stuff.
Stand-alone PHP Class for Data Sanitization and Validation
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-12