All Projects → jxlwqq → Id Validator

jxlwqq / Id Validator

Licence: mit
中华人民共和国居民身份证、中华人民共和国港澳居民居住证以及中华人民共和国台湾居民居住证号码验证工具(PHP 版)

Labels

Projects that are alternatives of or similar to Id Validator

Php Goose
Readability / Html Content / Article Extractor & Web Scrapping library written in PHP
Stars: ✭ 392 (-25.62%)
Mutual labels:  composer
Laravel Server Monitor
Server Monitoring Command for Laravel Applications
Stars: ✭ 424 (-19.54%)
Mutual labels:  composer
Symfony Console Autocomplete
Shell autocompletion for Symfony Console based scripts
Stars: ✭ 465 (-11.76%)
Mutual labels:  composer
Laravel Wallet
Easy work with virtual wallet
Stars: ✭ 401 (-23.91%)
Mutual labels:  composer
Bank Card Info
获取银行卡号的归属信息
Stars: ✭ 421 (-20.11%)
Mutual labels:  composer
Koa Webpack
Development and Hot Reload Middleware for Koa2
Stars: ✭ 429 (-18.6%)
Mutual labels:  composer
Coastercms
The repository for Coaster CMS (coastercms.org), a full featured, Laravel based Content Management System
Stars: ✭ 380 (-27.89%)
Mutual labels:  composer
Local Php Security Checker
PHP security vulnerabilities checker
Stars: ✭ 482 (-8.54%)
Mutual labels:  composer
Openapi Sdk Php
Alibaba Cloud SDK for PHP
Stars: ✭ 423 (-19.73%)
Mutual labels:  composer
Phpuseragent
Lightning Fast, Minimalist PHP User Agent String Parser.
Stars: ✭ 451 (-14.42%)
Mutual labels:  composer
Anti Xss
㊙️ AntiXSS | Protection against Cross-site scripting (XSS) via PHP
Stars: ✭ 403 (-23.53%)
Mutual labels:  composer
Docker Laravel
🐳 Build a simple laravel development environment with docker-compose.
Stars: ✭ 415 (-21.25%)
Mutual labels:  composer
Composer Registry Manager
🛠 🔨 Composer registry manager that help to easily switch to the composer repository you want.
Stars: ✭ 448 (-14.99%)
Mutual labels:  composer
Dog Ceo Api
The API hosted at dog.ceo
Stars: ✭ 393 (-25.43%)
Mutual labels:  composer
Medoo
The lightweight PHP database framework to accelerate the development.
Stars: ✭ 4,463 (+746.87%)
Mutual labels:  composer
Easytbk
淘客5合一SDK,支持淘宝联盟、京东联盟、多多进宝、唯品会、苏宁
Stars: ✭ 383 (-27.32%)
Mutual labels:  composer
Performance
⏱ PHP performance tool analyser your script on time, memory usage and db query. Support Laravel and Composer for web, web console and command line interfaces.
Stars: ✭ 429 (-18.6%)
Mutual labels:  composer
Acf Builder
An Advanced Custom Field Configuration Builder
Stars: ✭ 492 (-6.64%)
Mutual labels:  composer
Laravel React
Laravel 8 and React 17 boilerplate
Stars: ✭ 472 (-10.44%)
Mutual labels:  composer
Laravel Kit
A desktop Laravel admin panel app
Stars: ✭ 440 (-16.51%)
Mutual labels:  composer

IdValidator.php

中华人民共和国居民身份证中华人民共和国港澳居民居住证以及中华人民共和国台湾居民居住证号码验证工具(PHP Composer 版)支持 15 位与 18 位号码。

Build Status StyleCI Scrutinizer Code Quality Maintainability FOSSA Status 996.icu

安装

composer require "jxlwqq/id-validator"

注:如果 require 失败,解决方案见 #13

使用

440308199901101512610104620927690 示例大陆居民身份证均为随机生成的假数据,如撞车,请联系删除。 810000199408230021830000199201300022 示例港澳台居民居住证为北京市公安局公布的居住证样式号码。

验证身份证号合法性

验证身份证号是否合法,合法返回 true,不合法返回 false

use Jxlwqq\IdValidator\IdValidator;

$idValidator = new IdValidator();
$idValidator->isValid('440308199901101512'); // 大陆居民身份证 18 位
$idValidator->isValid('610104620927690');    // 大陆居民身份证 15 位
$idValidator->isValid('810000199408230021'); // 港澳居民居住证 18 位
$idValidator->isValid('830000199201300022'); // 台湾居民居住证 18 位

获取身份证号信息

当身份证号合法时,返回分析信息(地区、出生日期、星座、生肖、性别、校验位),不合法返回 false

use Jxlwqq\IdValidator\IdValidator;

$idValidator = new IdValidator();
$idValidator->getInfo('440308199901101512'); // 18 位
$idValidator->getInfo('610104620927690');    // 15 位

返回信息格式如下:

[
'addressCode'   => '440308',                    // 地址码   
'abandoned'     => 0,                           // 地址码是否废弃,1 为废弃的,0 为正在使用的
'address'       => '广东省深圳市盐田区',           // 地址
'addressTree'  => ['广东省', '深圳市', '盐田区']  // 省市区三级列表
'birthdayCode'  => '1999-01-10',                // 出生日期
'constellation' => '水瓶座',                     // 星座
'chineseZodiac' => '卯兔',                       // 生肖
'sex'           => 1,                           // 性别,1 为男性,0 为女性
'length'        => 18,                          // 号码长度
'checkBit'      => '2',                         // 校验码
]

注:判断地址码是否废弃的依据是中华人民共和国行政区划代码历史数据集,本数据集的采集源来自:中华人民共和国民政部,每年更新一次。本数据集采用 csv 格式存储,方便大家进行数据分析或者开发其他语言的版本。

生成可通过校验的假数据

伪造符合校验的身份证:

fakeId() 方法有 4 个可选参数:

  • $eighteen 是否生成 18 位号码,默认为 true
  • $address 地址,即省市县三级地区官方全称,如北京市台湾省香港特别行政区深圳市黄浦区等,默认或参数非法,则生成合法的随机地址;
  • $birthday 出生日期,如 200019880119990101 等,默认或参数非法,则生成合法的随机出生日期;
  • $sex 性别,1 为男性,0 为女性,默认或参数非法,则生成合法的随机性别;
use Jxlwqq\IdValidator\IdValidator;

$idValidator = new IdValidator();
$idValidator->fakeId();                                    // 18 位
$idValidator->fakeId(false);                               // 15 位
$idValidator->fakeId(true, '上海市', '2000', 1);            // 生成出生于 2000 年上海市的男性居民身份证
$idValidator->fakeId(true, '南山区', '1999', 0);            // 生成出生于 1999 年广东省深圳市南山区的女性居民身份证
$idValidator->fakeId(true, '江苏省', '200001', 1));         // 生成出生于 2000 年 1 月江苏省的男性居民身份证
$idValidator->fakeId(true, '厦门市', '199701', 0));         // 生成出生于 1997 年 1 月福建省厦门市的女性居民身份证
$idValidator->fakeId(true, '台湾省', '20131010', 0);        // 生成出生于 2013 年 10 月 10 日台湾省的女性居民居住证
$idValidator->fakeId(true, '香港特别行政区', '19970701', 0); // 生成出生于 1997 年 7 月 1 日香港特别行政区的女性居民居住证

升级身份证号码

15 位号码升级为 18 位:

use Jxlwqq\IdValidator\IdValidator;

$idValidator = new IdValidator();
$idValidator->upgradeId('610104620927690'); // 15 位号码升级为 18 位

参考资料

Change Log

  • 1.1.0 身份证号返回信息新增生肖和星座内容;

  • 1.2.0 支持港澳台居民居住证;

  • 1.3.0 行政区划代码(地址码)数据改由从中华人民共和国民政部官方网站获取;

  • 1.4.0 支持查询因行政区变更而废弃的地址码;

  • 1.4.2 fakeId() 方法增加可选参数;

  • 1.4.11 支持 15 位身份证号码升级为 18 位;

  • 1.4.18 getInfo() 返回值新增省市区三级列表

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].