phprsa/id-validator
Composer 安装命令:
composer require phprsa/id-validator
包简介
Professional South African RSA ID Number Validation Library with Luhn algorithm, date validation, and component extraction
README 文档
README
# **PHP RSA ID Validator**
A professional, lightweight PHP library for validating South African ID numbers. It performs full structural checks, validates birth dates, determines gender, identifies citizenship, and verifies the Luhn check digit. Ideal for forms, authentication systems, HR platforms, and any application requiring reliable South African ID verification.
Features
- Validates full RSA ID format (YYMMDDSSSGC A)
- Birth date extraction with automatic century detection
- Gender identification based on sequence number
- Citizen vs resident status
- Full Luhn algorithm check digit validation
- JSON API support
Installation
Using Composer
composer require phprsa/id-validator
Manual Load
If you’re not using Composer, include the file directly:
require 'vendor/phprsa/id-validator/src/RsaIdValidator.php';
Usage Example
use PhpRsaIdValidator\RsaIdValidator; $validator = new RsaIdValidator(); $result = $validator->validate('9001014800085'); if ($result['valid']) { echo "ID is valid"; } else { echo "Error: " . $result['error']; }
API Endpoint
This project includes a working API endpoint for remote validation.
id-api.php
<?php require __DIR__ . '/vendor/autoload.php'; use PhpRsaIdValidator\RsaIdValidator; header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true); $id = $data['id'] ?? null; if (!$id) { echo json_encode([ 'success' => false, 'error' => 'No ID number supplied' ]); exit; } $validator = new RsaIdValidator(); echo json_encode($validator->validate($id), JSON_PRETTY_PRINT);
Example Request
POST /id-api.php
Content-Type: application/json
{
"id": "9001014800085"
}
Example Response
{
"valid": true,
"id_number": "9001014800085",
"date_of_birth": "1990-01-01",
"gender": "Male",
"citizenship": "SA Citizen",
"check_digit": 5
}
Browser Test Page (id.php)
A small interface for manual validation:
<?php require __DIR__ . '/vendor/autoload.php'; use PhpRsaIdValidator\RsaIdValidator; $id = $_GET['id'] ?? null; $validator = new RsaIdValidator(); $result = $id ? $validator->validate($id) : null; ?> <!DOCTYPE html> <html> <head> <title>RSA ID Validator</title> <style> body { font-family: Arial; margin: 40px; } input { padding: 8px; width: 260px; } button { padding: 8px 18px; } .box { margin-top: 20px; padding: 15px; border-radius: 6px; } .ok { background: #d4edda; } .bad { background: #f8d7da; } </style> </head> <body> <h2>RSA ID Validator</h2> <form method="GET"> <input type="text" name="id" placeholder="Enter ID" value="<?= htmlspecialchars($id) ?>"> <button type="submit">Check</button> </form> <?php if ($result): ?> <div class="box <?= $result['valid'] ? 'ok' : 'bad' ?>"> <?php if ($result['valid']): ?> <strong>Valid</strong><br><br> ID: <?= $result['id_number'] ?><br> DOB: <?= $result['date_of_birth'] ?><br> Gender: <?= $result['gender'] ?><br> Citizenship: <?= $result['citizenship'] ?><br> Check Digit: <?= $result['check_digit'] ?><br> <?php else: ?> <strong>Invalid</strong><br><br> <?= $result['error'] ?> <?php endif; ?> </div> <?php endif; ?> </body> </html>
Test Client (test-api.php)
<?php $url = "https://yourdomain.com/id-api.php"; $payload = json_encode(["id" => "9001014800085"]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); $response = curl_exec($ch); curl_close($ch); echo "<pre>"; print_r(json_decode($response, true)); echo "</pre>";
.gitignore
vendor/
composer.lock
.env
*.log
.DS_Store
.idea/
phprsa/id-validator 适用场景与选型建议
phprsa/id-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validator」 「validation」 「id」 「rsa」 「luhn」 「South Africa」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phprsa/id-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phprsa/id-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phprsa/id-validator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Validation and Sanitization Library
Extension for Opis JSON Schema
PHP laravel extension rsa
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.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 45
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-25