Giter VIP home page Giter VIP logo

id-validator's Introduction

id-validator

简体中文 | ENGLISH

China ID number validator. - **身份证号验证器。

tests codecov Go Report Card GoDoc GitHub release GitHub license

功能

  • 验证**身份证号
  • 获取身份证号信息
  • 升级 15 位身份证号为 18 位
  • 伪造符合校验的身份证号

环境要求

  • Go >= 1.11

安装

$ go get -u github.com/guanguans/id-validator

使用

这只是一个快速介绍, 请查看 GoDoc 获得详细信息。

package main

import (
    idvalidator "github.com/guanguans/id-validator"
    "gopkg.in/ffmt.v1"
)

func main() {
    // 验证身份证号合法性
    ffmt.P(idvalidator.IsValid("500154199301135886", true))  // 严格模式验证大陆居民身份证18位
    ffmt.P(idvalidator.IsValid("500154199301135886", false)) // 非严格模式验证大陆居民身份证18位
    ffmt.P(idvalidator.IsValid("11010119900307803X", false)) // 大陆居民身份证末位是X18位
    ffmt.P(idvalidator.IsValid("610104620927690", false))    // 大陆居民身份证15位
    ffmt.P(idvalidator.IsValid("810000199408230021", false)) // 港澳居民居住证18位
    ffmt.P(idvalidator.IsValid("830000199201300022", false)) // **居民居住证18位

    // 获取身份证号信息
    ffmt.P(idvalidator.GetInfo("500154199301135886", true))  // 严格模式获取身份证号信息
    ffmt.P(idvalidator.GetInfo("500154199301135886", false)) // 非严格模式获取身份证号信息
    // []interface {}[
    //     github.com/guanguans/id-validator.IdInfo{          // 身份证号信息
    //         AddressCode: int(500154)                           // 地址码
    //         Abandoned:   int(0)                                // 地址码是否废弃:1为废弃的,0为正在使用的
    //         Address:     string("重庆市市辖区开州区")             // 地址
    //         AddressTree: []string[                             // 省市区三级列表
    //             string("重庆市")                                    // 省
    //             string("市辖区")                                    // 市
    //             string("开州区")                                    // 区
    //         ]
    //         Birthday:      <1993-01-13 00:00:00 +0800 CST>     // 出生日期
    //         Constellation: string("摩羯座")                     // 星座
    //         ChineseZodiac: string("酉鸡")                       // 生肖
    //         Sex:           int(0)                              // 性别:1为男性,0为女性
    //         Length:        int(18)                             // 号码长度
    //         CheckBit:      string("6")                         // 校验码
    //     }
    //     <nil>                                              // 错误信息
    // ]

    // 生成可通过校验的假身份证号
    ffmt.P(idvalidator.FakeId())                                  // 随机生成
    ffmt.P(idvalidator.FakeRequireId(true, "江苏省", "200001", 1)) // 生成出生于2000年1月江苏省的男性居民身份证

    // 15位号码升级为18位
    ffmt.P(idvalidator.UpgradeId("610104620927690"))
    // []interface {}[
    // 	string("610104196209276908") // 升级后号码
    // 	<nil>                        // 错误信息
    // ]
}

测试

$ make test

变更日志

请参阅 CHANGELOG 获取最近有关更改的更多信息。

贡献指南

请参阅 CONTRIBUTING 有关详细信息。

安全漏洞

请查看我们的安全政策了解如何报告安全漏洞。

贡献者

相关项目

参考资料

协议

MIT 许可证(MIT)。有关更多信息,请参见协议文件

id-validator's People

Contributors

117503445 avatar dependabot[bot] avatar guanguans avatar zongrzhang avatar zzhaoh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.