You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.8 KiB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # id-validator
  2. [简体中文](README.md) | [ENGLISH](README-EN.md)
  3. > 中国身份证号验证。
  4. [![Tests](https://github.com/guanguans/id-validator/workflows/Tests/badge.svg)](https://github.com/guanguans/id-validator/actions)
  5. [![gocover.io](https://gocover.io/_badge/github.com/guanguans/id-validator)](https://gocover.io/github.com/guanguans/id-validator)
  6. [![Go Report Card](https://goreportcard.com/badge/github.com/guanguans/id-validator)](https://goreportcard.com/report/github.com/guanguans/id-validator)
  7. [![GoDoc](https://godoc.org/github.com/guanguans/id-validator?status.svg)](https://godoc.org/github.com/guanguans/id-validator)
  8. [![GitHub release](https://img.shields.io/github/tag/guanguans/id-validator.svg)](https://github.com/guanguans/id-validator/releases)
  9. [![GitHub license](https://img.shields.io/github/license/guanguans/id-validator.svg)](https://github.com/guanguans/id-validator/blob/master/LICENSE)
  10. ## 功能
  11. * 中国身份证号验证
  12. * 获取身份证号信息
  13. * 升级 15 位身份证号为 18 位
  14. * 伪造符合校验的身份证号
  15. ## 环境要求
  16. * Go >= 1.11
  17. ## 安装
  18. ``` shell script
  19. $ go get -u github.com/guanguans/id-validator
  20. ```
  21. ## 使用
  22. 这只是一个快速介绍, 请查看 [GoDoc](https://godoc.org/github.com/guanguans/id-validator) 获得详细信息。
  23. ``` go
  24. package main
  25. import (
  26. idvalidator "github.com/guanguans/id-validator"
  27. "gopkg.in/ffmt.v1"
  28. )
  29. func main() {
  30. // 验证身份证号合法性
  31. ffmt.P(idvalidator.IsValid("440308199901101512")) // 大陆居民身份证18位
  32. ffmt.P(idvalidator.IsValid("610104620927690")) // 大陆居民身份证15位
  33. ffmt.P(idvalidator.IsValid("810000199408230021")) // 港澳居民居住证18位
  34. ffmt.P(idvalidator.IsValid("830000199201300022")) // 台湾居民居住证18位
  35. // 获取身份证号信息
  36. ffmt.P(idvalidator.GetInfo("440308199901101512"))
  37. // []interface {}[
  38. // github.com/guanguans/id-validator.IdInfo{ // 身份证号信息
  39. // AddressCode: int(440308) // 地址码
  40. // Abandoned: int(0) // 地址码是否废弃:1为废弃的,0为正在使用的
  41. // Address: string("广东省深圳市盐田区") // 地址
  42. // AddressTree: []string[ // 省市区三级列表
  43. // string("广东省") // 省
  44. // string("深圳市") // 市
  45. // string("盐田区") // 区
  46. // ]
  47. // Birthday: <1999-01-10 00:00:00 +0000 UTC> // 出生日期
  48. // Constellation: string("摩羯座") // 星座
  49. // ChineseZodiac: string("卯兔") // 生肖
  50. // Sex: int(1) // 性别:1为男性,0为女性
  51. // Length: int(18) // 号码长度
  52. // CheckBit: string("2") // 校验码
  53. // }
  54. // <nil> // 错误信息
  55. // ]
  56. // 生成可通过校验的假身份证号
  57. ffmt.P(idvalidator.FakeId()) // 随机生成
  58. ffmt.P(idvalidator.FakeRequireId(true, "江苏省", "200001", 1)) // 生成出生于2000年1月江苏省的男性居民身份证
  59. // 15位号码升级为18位
  60. ffmt.P(idvalidator.UpgradeId("610104620927690"))
  61. // []interface {}[
  62. // string("610104196209276908") // 升级后号码
  63. // <nil> // 错误信息
  64. // ]
  65. }
  66. ```
  67. ## 测试
  68. ``` bash
  69. $ make test
  70. ```
  71. ## 变更日志
  72. 请参阅 [CHANGELOG](CHANGELOG.md) 获取最近有关更改的更多信息。
  73. ## 贡献指南
  74. 请参阅 [CONTRIBUTING](.github/CONTRIBUTING.md) 有关详细信息。
  75. ## 安全漏洞
  76. 请查看[我们的安全政策](../../security/policy)了解如何报告安全漏洞。
  77. ## 贡献者
  78. * [guanguans](https://github.com/guanguans)
  79. * [所有贡献者](../../contributors)
  80. ## 相关项目
  81. * [jxlwqq/id-validator](https://github.com/jxlwqq/id-validator),jxlwqq
  82. * [jxlwqq/id-validator.py](https://github.com/jxlwqq/id-validator.py),jxlwqq
  83. * [mc-zone/IDValidator](https://github.com/mc-zone/IDValidator),mc-zone
  84. * [renyijiu/id_validator](https://github.com/renyijiu/id_validator),renyijiu
  85. ## 参考资料
  86. * [中华人民共和国公民身份号码](https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码)
  87. * [中华人民共和国民政部:行政区划代码](http://www.mca.gov.cn/article/sj/xzqh/)
  88. * [中华人民共和国行政区划代码历史数据集](https://github.com/jxlwqq/address-code-of-china)
  89. * [国务院办公厅关于印发《港澳台居民居住证申领发放办法》的通知](http://www.gov.cn/zhengce/content/2018-08/19/content_5314865.htm)
  90. * [港澳台居民居住证](https://zh.wikipedia.org/wiki/港澳台居民居住证)
  91. ## 协议
  92. MIT 许可证(MIT)。有关更多信息,请参见[协议文件](LICENSE)。