中华人民共和国居民身份证、中华人民共和国港澳居民居住证以及中华人民共和国**居民居住证号码验证工具(PHP Composer 版)支持 15 位与 18 位号码。
composer require "jxlwqq/id-validator"
注:如果 require 失败,解决方案见 #13。
440308199901101512
和610104620927690
示例大陆居民身份证均为随机生成的假数据,如撞车,请联系删除。810000199408230021
和830000199201300022
示例港澳台居民居住证为北京市公安局公布的居住证样式号码。
验证身份证号是否合法,合法返回 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
出生日期,如2000
、198801
、19990101
等,默认或参数非法,则生成合法的随机出生日期;$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 位
-
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()
返回值新增省市区三级列表
MIT
id-validator's People
Forkers
greatxj zhanglei hainuo zhurongjian junhuz forging2012 xisss happyyb skylei lian123520 javascriptexample jerlisen teddymail jackytedy itpointerme brisk21 dbank888 872409 edward-ng-duke peasshoter xhhphp fengshow12345 qinhehan ivesein lypeng29 chinphy benjamesbabala justknow23 smallweiwei visionyimian xqfz zjing123 mio-next berrythinking jhhphp 529834149 huizhang-php zhenyangze he1dan carner hbjlamp kaka900 generalbao feiyizhan kagomelee lianzh lugensen wlw330296385 jingshenbusi6530 zxing0214 soul-key caihuar xjchengo sky8652 lwp145 chplain xinjiangqingmang steelzy yangzming var100 agentptx qingmang caoruister qtsunami asuratu gorgeno hujianjian187 davidxuuts liuxingke alantianx yangweijie lyhiving chinaguopeng timeisaway jarvis-starkz jefferyjob askme-gpt auh1st 3137695831 wmlc chareasy turingtaoist follow-the-vine-to-get-to-the-melon liuzhengjian pengyuanhong caifeihu stevehum14 xl129 barlowhaydnb zaxw niclalalla chendujin orxz lbg-sys dshawhub pope-l anhaoid-validator's Issues
632825开头身份证校验有误
632824、632825、632826开头的身份证校验都不行
重庆地区的身份证判断是不是有问题
97年之前的都显示错误
430419开头身份证校验有误
这个开头的身份证,一直提示校验错误,查了一下相关报道,知道是历史遗留问题,是有效的,不知道程序上能不能兼容一下。
http://news.cctv.com/society/20070824/100579.shtml 央视新闻
https://zhidao.baidu.com/question/1303352281702656259.html 百度知道
Testing with PHP 8.1 version
Nov 25 2021 GA
无法获取身份证信息
632826201612050015 该身份证号真实有效 但该组件校验不通过
代码里是不是应该去掉时间线的判断?
找到一身份证是 4110821989 开头的,地址是河南省长葛市。
但用这个插件获取到的河南省许昌市,看了下代码,是根据时间线判断了一下取值,导致没取到 411082 对应的长葛市
另外看 行政区划代码 http://www.mca.gov.cn/article/sj/xzqh/1980/?2 长葛市又的确是1995年新增上去的
代码里是不是应该去掉时间线的判断,只需要用最新的 行政区划代码 就可以了
包安装问题
通过 composer 安装,data
文件夹压根儿就没装。
生肖计算问题
生肖一般是根据农历计算的,库里是按照阳历计算的
发现有身份证的行政区划在文件里查不到,然后去民政部的网站上也查不到。
身份证开头 441282 ,确认了身份证的正确性,走公安接口可以通过,但是在行政区划的文件里找不到,我到民政部网站里去翻也找不到。现在很尴尬,不知道如何处理,又不希望自己手动改 vendor 的源码造成后续维护困难。可以发布一个类似于配置文件的内容,将这些特殊的行政区划加入到验证中么?
34240120010721571X
34240120010721571X 验证不通过~~~
320219开头的识别有误
RT
test on php 7.4
如果用户输入的身份证号码为“军官证123456”等含两个以上的汉字时,程序报错。
报错信息如下所示:
PHP Fatal error: Uncaught Error: Call to a member function format() on boolean in ...\jxlwqq\id-validator\src\Checker.php:111
Stack trace:
#0 ...\jxlwqq\id-validator\src\IdValidator.php(40): Jxlwqq\IdValidator\IdValidator->_checkBirthdayCode('19\xE8\xAF\x81144')
#1 test.php(8): Jxlwqq\IdValidator\IdValidator->isValid('\xE5\x86\x9B\xE5\xAE\x98\xE8\xAF\x81144125')
#2 {main}
thrown in ...\jxlwqq\id-validator\src\Checker.php on line 111
test on php 8
地址码:数据更新至2019年08月
无法安装此包
composer require "jxlwqq/id-validator"
报错
Could not find package jxlwqq/id-validator. It was however found via repository search, which indicates a consistency issue with the repository.
阿里云 laravel 官方源 都是试过了
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.