npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@daoxin/card

v0.0.6

Published

一款基于大中华区的身份证规则验证库

Downloads

5

Readme

card

一款基于中国大中华区的身份证规则验证库

一、如何使用

$ npm i @daoxin/card  //或 yarn add @daoxin/card


const Card = require('@daoxin/card').default   // 获取 import Card from '@daoxin/card'

console.log('身份证no',new Card("513022199509151233").isValid()) //身份证no false
console.log('身份证ok',new Card("513022199509151234").isValid()) //身份证ok true
console.log('身份证ok_info',new Card("173022199509151234",true).isValid()) // 身份证ok_info { valid: false }
console.log('身份证ok_info',new Card("513022199509151234",true).isValid())  //身份证ok_info {valid: true,id: '513022199509151234',length: 18,y: '1995',m: '09',d: '15',sex: '男',province: '四川省'}
console.log('身份证no_info',new Card("513022199519131234",true).isValid()) //身份证no_info { valid: false }
console.log('身份证no_info',new Card("16302219930910123",true).isValid()) //身份证no_info { valid: false }
console.log('身份证no',new Card().isValid()) //身份证no false

二、身份证检验原理

编排规则

身份证号码是由18位数字组成的,它们分别表示:

  • 前1、2位数字表示:所在省份的代码;

  • 第3、4位数字表示:所在城市的代码;

  • 第5、6位数字表示:所在区县的代码;

  • 第7~14位数字表示:出生年(7~10)月(11~12)日(13~14);

  • 第15、16位数字表示:所在地的派出所的代码

  • 第17位数字表示性别:奇数表示男性,偶数表示女性

  • 第18位数字是校检码:校检码可以是0~9的数字,有时也用x表示

  • -> 号码的结构: 公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。

  • -> 地址码:表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行 统计局百度

  • -> 出生日期码:表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日代码之间不用分隔符。

  • -> 顺序码:表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配给女性。

尾号X的意义

身份证的号码是按照国家标准编制的,由18位组成:前六位为行政区划代码,第七至第十四位为出生日期码,第15至17位为顺序码,第18位为校验码。

作为尾号的校验码,是由号码编制单位按统一的公式计算出来的,如果某人的尾号是0-9,都不会出现X,但如果尾号是10,那么就得用X来代替,因为如果用10做尾号,那么此人的身份证就变成了19位,而19位的号码违反了国家标准,并且我国的计算机应用系统也不承认19位的身份证号码。Ⅹ是罗马数字的10,用X来代替10,可以保证公民的身份证符合国家标准。

身份证号异同

  • 15位的身份证号: dddddd yymmdd xx p

  • 18位的身份证号: dddddd yyyymmdd xx p y

  • 其中dddddd为地址码(省地县三级)

  • 18位中的和15位中的不完全相同:

  • yymmdd yyyymmdd 为出生年月日;

  • xx为顺号类编码;

  • p为性别;

  • 前17位的ascii码值经位移、异或运算,结果不在0-9的令其为x。

  • 18位号码中末尾的y为校验码,可参考算法(身份证最后一位校验码算法如下即第18位数字的计算方法):

 . 将前面的身份证号码17位数分别乘以不同的系数。从第1位到第17位的系数分别为:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2

 . 将这17位数字和系数相乘的结果相加(17个乘积相加)

 . 将相加后的和除以11并得到余数(用加出来和除以11看余数是多少)

 . 余数只可能为0 1 2 3 4 5 6 7 8 9 10这11个数字,其分别对应的身份证最后一位校验码为 1 0 X 9 8 7 6 5 4 3 2

 . 通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2
  • 校验码: y -> 该位数值可通过前17位计算获得,具体如下:

  • 18位号码加权因子为(从右到左): Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,1 ]

  • 验证位: Y = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ]

  • 校验位计算公式:Y_P = mod( ∑(Ai×Wi),11 )

  • i为身份证号码从右往左数的2...18位

  • Y_P为脚丫校验码所在校验码数组位置

各省代码含义


华北:北京11,天津12,河北13,山西14,内蒙古15

东北: 辽宁21,吉林22,黑龙江23

华东: 上海31,江苏32,浙江33,安徽34,福建35,江西36,山东37

华中: 河南41,湖北42,湖南43

华南: 广东44,广西45,海南46

西南: 四川51,贵州52,云南53,西藏54,重庆50

西北: 陕西61,甘肃62,青海63,宁夏64,新疆65

特别:台湾71,香港81,澳门82


一、四个直辖市:
1、北京11
2、天津12
3、上海31
4、重庆50

二、五个自治区:
1、内蒙古15
2、新疆65
3、西藏54
4、宁夏64
5、广西45

三、两个特别行政区:
1、香港特别行政区810000
2、澳门特别行政区820000

四、23个省 :
1、黑龙江省23
2、吉林省22
3、辽宁省21
4、河北省13
5、山西省14
6、青海省63
7、山东省37
8、河南省41
9、江苏省32
10、安徽省34
11、浙江省33
12、福建省35
13、江西省36
14、湖南省43
15、湖北省42
16、广东省44
17、海南省46
18、甘肃省62
19、陕西省61
20、四川省51
21、贵州省52
22、云南省53
23、台湾省710000