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-EN.md 4.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # id-validator
  2. [简体中文](README.md) | [ENGLISH](README-EN.md)
  3. > China ID number verification.
  4. ## Features
  5. * China ID number verification
  6. * Get ID number information
  7. * Upgrade 15-digit ID number to 18
  8. * Forged ID number that meets the verification
  9. ## Requirement
  10. * Go >= 1.11
  11. ## Installation
  12. ``` shell script
  13. $ go get -u github.com/guanguans/id-validator
  14. ```
  15. ## Usage
  16. This is just a quick introduction, view the [GoDoc](https://godoc.org/github.com/guanguans/id-validator) for details.
  17. Let's start with a trivial example:
  18. ``` go
  19. package main
  20. import (
  21. idvalidator "github.com/guanguans/id-validator"
  22. "gopkg.in/ffmt.v1"
  23. )
  24. func main() {
  25. // 验证身份证号合法性
  26. ffmt.P(idvalidator.IsValid("440308199901101512")) // 大陆居民身份证18位
  27. ffmt.P(idvalidator.IsValid("610104620927690")) // 大陆居民身份证15位
  28. ffmt.P(idvalidator.IsValid("810000199408230021")) // 港澳居民居住证18位
  29. ffmt.P(idvalidator.IsValid("830000199201300022")) // 台湾居民居住证18位
  30. // 获取身份证号信息
  31. ffmt.P(idvalidator.GetInfo("440308199901101512"))
  32. // []interface {}[
  33. // github.com/guanguans/id-validator.IdInfo{ // 身份证号信息
  34. // AddressCode: int(440308) // 地址码
  35. // Abandoned: int(0) // 地址码是否废弃:1为废弃的,0为正在使用的
  36. // Address: string("广东省深圳市盐田区") // 地址
  37. // AddressTree: []string[ // 省市区三级列表
  38. // string("广东省") // 省
  39. // string("深圳市") // 市
  40. // string("盐田区") // 区
  41. // ]
  42. // Birthday: <1999-01-10 00:00:00 +0000 UTC> // 出生日期
  43. // Constellation: string("摩羯座") // 星座
  44. // ChineseZodiac: string("卯兔") // 生肖
  45. // Sex: int(1) // 性别:1为男性,0为女性
  46. // Length: int(18) // 号码长度
  47. // CheckBit: string("2") // 校验码
  48. // }
  49. // <nil> // 错误信息
  50. // ]
  51. // 生成可通过校验的假身份证号
  52. ffmt.P(idvalidator.FakeId()) // 随机生成
  53. ffmt.P(idvalidator.FakeRequireId(true, "江苏省", "200001", 1)) // 生成出生于2000年1月江苏省的男性居民身份证
  54. // 15位号码升级为18位
  55. ffmt.P(idvalidator.UpgradeId("610104620927690"))
  56. // []interface {}[
  57. // string("610104196209276908") // 升级后号码
  58. // <nil> // 错误信息
  59. // ]
  60. }
  61. ```
  62. ## Testing
  63. ``` bash
  64. $ make test
  65. ```
  66. ## Changelog
  67. Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
  68. ## Contributing
  69. Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
  70. ## Security Vulnerabilities
  71. Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
  72. ## Credits
  73. * [guanguans](https://github.com/guanguans)
  74. * [All Contributors](../../contributors)
  75. ## Related projects
  76. * [jxlwqq/id-validator](https://github.com/jxlwqq/id-validator), by jxlwqq
  77. * [jxlwqq/id-validator.py](https://github.com/jxlwqq/id-validator.py), by jxlwqq
  78. * [mc-zone/IDValidator](https://github.com/mc-zone/IDValidator), by mc-zone
  79. * [renyijiu/id_validator](https://github.com/renyijiu/id_validator), by renyijiu
  80. ## Reference material
  81. * [People's Republic of China citizenship number](https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码)
  82. * [Ministry of Civil Affairs of the People's Republic of China: Administrative division code](http://www.mca.gov.cn/article/sj/xzqh/)
  83. * [Historical data set of administrative division codes of the People's Republic of China](https://github.com/jxlwqq/address-code-of-china)
  84. * [Notice of the General Office of the State Council on Issuing the Measures for the Application and Issuance of Residence Permits for Hong Kong, Macao and Taiwan Residents](http://www.gov.cn/zhengce/content/2018-08/19/content_5314865.htm)
  85. * [Residence Permit for Hong Kong, Macao and Taiwan Residents](https://zh.wikipedia.org/wiki/港澳台居民居住证)
  86. ## License
  87. The MIT License (MIT). Please see [License File](LICENSE) for more information.