https://github.com/sleagon/chinaid
🇨🇳中国大陆身份证号解析/校验
https://github.com/sleagon/chinaid
checker china id identity-card parser shen-f-z
Last synced: 13 days ago
JSON representation
🇨🇳中国大陆身份证号解析/校验
- Host: GitHub
- URL: https://github.com/sleagon/chinaid
- Owner: sleagon
- License: mit
- Created: 2018-04-25T13:34:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-07T02:59:40.000Z (almost 4 years ago)
- Last Synced: 2025-08-13T18:16:11.747Z (6 months ago)
- Topics: checker, china, id, identity-card, parser, shen-f-z
- Language: Go
- Homepage:
- Size: 74.2 KB
- Stars: 22
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# CHINA ID(中国大陆身份证)
[](https://travis-ci.org/sleagon/chinaid) [](https://goreportcard.com/report/github.com/sleagon/chinaid) [](https://godoc.org/github.com/sleagon/chinaid) [](https://opensource.org/licenses/MIT)
> 校验、解析中国大陆身份证号
## 身份证号校验
```go
package main
import (
"log"
"github.com/sleagon/chinaid"
)
func main() {
id := chinaid.IDCard("420683199006041237")
result := id.Valid()
log.Println(">>>>", result)
}
```
## 身份证信息解析
```go
package main
import (
"log"
"github.com/sleagon/chinaid"
)
func main() {
id := chinaid.IDCard("420683199006041237")
result, err := id.Decode()
if err != nil {
log.Println("非法身份证号")
return
}
log.Println(">>>>", result)
}
```
## 结果示例
```json
{
"sex": 1,
"code": 420683,
"district": "枣阳市",
"city": "襄阳市",
"province": "湖北省",
"birthday": "1990-06-04T00:00:00Z"
}
```
## 地域映射
身份证里的地域码往地域转换的映射表来自[中华人民共和国民政部][1]官网,本项目里目前用的版本是2020年7月更新的[版本](http://www.mca.gov.cn//article/sj/xzqh/2020/2020/20200908007001.html),后续会不定期更新。
## 依赖示例
```bash
go get github.com/sleagon/chinaid
```
> dep
```yml
[[constraint]]
name = "github.com/sleagon/chinaid"
version = "0.3"
```
[1]: http://www.mca.gov.cn/