{"id":21102185,"url":"https://github.com/renyijiu/id_validator","last_synced_at":"2025-05-16T18:34:40.155Z","repository":{"id":56877294,"uuid":"153891299","full_name":"renyijiu/id_validator","owner":"renyijiu","description":"A Ruby Gem For Chinese Mainland Personal ID Card Validation","archived":false,"fork":false,"pushed_at":"2018-10-30T03:41:33.000Z","size":185,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-14T16:04:44.228Z","etag":null,"topics":["id-card","id-validator","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/id_validator","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renyijiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-20T09:46:37.000Z","updated_at":"2023-05-26T06:02:28.000Z","dependencies_parsed_at":"2022-08-20T11:31:07.304Z","dependency_job_id":null,"html_url":"https://github.com/renyijiu/id_validator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fid_validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fid_validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fid_validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fid_validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renyijiu","download_url":"https://codeload.github.com/renyijiu/id_validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225444688,"owners_count":17475354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["id-card","id-validator","ruby","ruby-gem"],"created_at":"2024-11-19T23:54:19.631Z","updated_at":"2024-11-19T23:54:20.319Z","avatar_url":"https://github.com/renyijiu.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/renyijiu/id_validator.svg?branch=master)](https://travis-ci.com/renyijiu/id_validator)\n[![Gem Version](https://badge.fury.io/rb/id_validator.svg)](https://badge.fury.io/rb/id_validator)\n[![Maintainability](https://api.codeclimate.com/v1/badges/c12676a3c0261956e06c/maintainability)](https://codeclimate.com/github/renyijiu/id_validator/maintainability)\n\n# IdValidator\n\n**中华人民共和国居民身份证** 、**中华人民共和国港澳居民居住证** 以及 **中华人民共和国台湾居民居住证** 号码验证工具（Ruby\n版）支持 15 位与 18 位号码。\n\n- [JavaScript 版本](https://github.com/mc-zone/IDValidator)\n- [PHP 版本](https://github.com/jxlwqq/id-validator)\n- [Python 版本](https://github.com/jxlwqq/id-validator.py)\n\n## 安装\n\n将下列代码增加到对应项目的Gemfile中：\n\n```ruby\ngem 'id_validator'\n```\n\n然后执行下列命令：\n\n    $ bundle\n\n或者，直接安装对应的gem包使用：\n\n    $ gem install id_validator\n\n## 使用\n\n   `440308199901101512` 和 `610104620927690`\n   \n   示例大陆居民身份证均为随机生成的假数据，如有看雷同，请联系删除。\n \n   `810000199408230021` 和 `830000199201300022`\n \n   示例港澳台居民居住证为北京市公安局公布的居住证样式号码。\n   \n### 验证身份证合法性\n\n验证身份证合法性，合法返回 `true`, 不合法返回 `false`\n\n```ruby\nIdValidator.is_valid?('440308199901101512') # =\u003e true, 大陆居民身份证 18 位\nIdValidator.is_valid?('610104620927690')    # =\u003e true, 大陆居民身份证 15 位\nIdValidator.is_valid?('810000199408230021') # =\u003e true, 港澳居民身份证 18 位\nIdValidator.is_valid?('830000199201300022') # =\u003e true, 台湾居民身份证 18 位\n```\n\n### 获取身份证号信息\n\n当身份证号合法时，返回分析信息（地区、出生日期、星座、生肖、性别、校验码），不合法时返回 `false`\n\n\n```ruby\n\nIdValidator.get_info('440308199901101512') # 大陆居民身份证 18 位\nIdValidator.get_info('610104620927690')    # 大陆居民身份证 15 位\n\n```\n返回信息格式如下：\n\n```ruby\n{\n    :address_code =\u003e \"440308\",                   # 地址码\n    :address =\u003e [\"广东省\", \"深圳市\", \"盐田区\"],      # 地址信息，三元组（省，市，区）\n    :abandoned =\u003e false,                         # 地址码是否已经废弃\n    :birthday_code =\u003e \"1999-01-10\",              # 出生日期\n    :constellation =\u003e \"摩羯座\",                   # 星座\n    :chinese_zodiac =\u003e \"卯兔\",                    # 生肖 \n    :sex =\u003e 1,                                   # 性别，0：女性，1：男性\n    :length =\u003e 18,                               # 号码长度 \n    :check_bit=\u003e\"2\"                              # 校验码\n}\n```\n \n\u003e 注：判断地址码是否废弃的依据是[中华人民共和国行政区划代码历史数据集](https://github.com/jxlwqq/address-code-of-china) ，本数据集的采集源来自：[中华人民共和国民政部](http://www.mca.gov.cn/article/sj/xzqh//1980/) ，每年更新一次。本数据集采用 csv 格式存储，方便大家进行数据分析或者开发其他语言的版本。\n\n### 生成可通过校验的假数据\n\n```ruby\nIdValidator.fake_id(eighteen = true, address = nil, birthday = nil, sex = nil)\n\nIdValidator.fake_id                                      # 18位 身份证\nIdValidator.fake_id(false)                               # 15位 身份证    \nIdValidator.fake_id(true, '上海市')                       # 18位 上海市居民身份证\nIdValidator.fake_id(true, '南山区', '1993')               # 18位 出生于 1993年 广东省深圳市南山区身份证\nIdValidator.fake_id(true, '江苏省', '199301')             # 18位 出生于 1993年01月 江苏省身份证\nIdValidator.fake_id(true, '厦门市', '19930101', 1)        # 18位 出生于 1993年01月01日 福建省厦门市男性身份证\nIdValidator.fake_id(true, '台湾省', '20131010', 0)        # 18位 出生于 2013年10月10日 台湾省女性身份证\nIdValidator.fake_id(true, '香港特别行政区', '20131010', 0)  # 18位 出生于 2013年10月10日 香港特别行政区女性身份证\n```\n\n### 身份证升级\n\n15 位号码升级为 18 位\n```ruby\nIdValidator.upgrade_id('610104620927690')\n=\u003e \"610104196209276908\"\n```\n \n## 参考资料\n\n- [中华人民共和国公民身份号码](https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码)\n\n- [中华人民共和国民政部：行政区划代码](http://www.mca.gov.cn/article/sj/xzqh/)\n\n- [中华人民共和国行政区划代码历史数据集](https://github.com/renyijiu/address-code-of-china)\n\n- [国务院办公厅关于印发《港澳台居民居住证申领发放办法》的通知](http://www.gov.cn/zhengce/content/2018-08/19/content_5314865.htm)\n\n- [港澳台居民居住证](https://zh.wikipedia.org/wiki/港澳台居民居住证)\n\n## 如何贡献\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n欢迎贡献相关代码或是提交你的使用反馈👏，另外请记得为你的代码编写测试。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenyijiu%2Fid_validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenyijiu%2Fid_validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenyijiu%2Fid_validator/lists"}