idvalidator

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2021 License: MIT Imports: 8 Imported by: 10

README

id-validator

中国身份证号验证、获取身份证号信息、升级 15 位身份证号为 18 位、伪造符合校验的身份证号。

Tests gocover.io Go Report Card GoDoc GitHub release GitHub license

Requirement

  • Go >= 1.11

Installation

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

Usage

This is just a quick introduction, view the GoDoc for details.

Let's start with a trivial example:

package main

import (
	"fmt"

	idvalidator "github.com/guanguans/id-validator"
)

func main() {

	// 验证身份证号合法性
	ffmt.P(idvalidator.IsValid("440308199901101512"))  // 大陆居民身份证18位
	ffmt.P(idvalidator.IsValid("610104620927690"))     // 大陆居民身份证15位
	ffmt.P(idvalidator.IsValid("810000199408230021"))  // 港澳居民居住证18位
	ffmt.P(idvalidator.IsValid("830000199201300022"))  // 台湾居民居住证18位

	// 获取身份证号信息
	ffmt.P(idvalidator.GetInfo("440308199901101512"))
	// []interface {}[
	// 	github.com/guanguans/id-validator.IdInfo{          // 身份证号信息
	// 		AddressCode: int(440308)                           // 地址码
	// 		Abandoned:   int(0)                                // 地址码是否废弃:1为废弃的,0为正在使用的
	// 		Address:     string("广东省深圳市盐田区")             // 地址
	// 		AddressTree: []string[                             // 省市区三级列表
	//			string("广东省")                                    // 省
	//			string("深圳市")                                    // 市
	//			string("盐田区")                                    // 区
	//		]
	// 		Birthday:      <1999-01-10 00:00:00 +0000 UTC>     // 出生日期
	// 		Constellation: string("摩羯座")                     // 星座
	// 		ChineseZodiac: string("卯兔")                       // 生肖
	// 		Sex:           int(1)                              // 性别:1为男性,0为女性
	// 		Length:        int(18)                             // 号码长度
	// 		CheckBit:      string("2")                         // 校验码
	// 	}
	// 	<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>                        // 错误信息
	// ]
}

Testing

$ go test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

相关项目

参考资料

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressCodeClassification

func AddressCodeClassification(addressCode string) string

地址码分类

func CheckAddressCode

func CheckAddressCode(addressCode string, birthdayCode string) bool

检查地址码

func CheckBirthdayCode

func CheckBirthdayCode(birthdayCode string) bool

检查出生日期码

func CheckIdArgument

func CheckIdArgument(id string) bool

检查ID参数

func CheckOrderCode

func CheckOrderCode(orderCode string) bool

检查顺序码

func DatePad

func DatePad(date string, category string) string

日期补全

func DatePipelineHandle

func DatePipelineHandle(date string, category string) string

日期处理

func FakeId

func FakeId() string

生成假身份证号码

func FakeRequireId

func FakeRequireId(isEighteen bool, address string, birthday string, sex int) string

按要求生成假身份证号码 isEighteen 是否生成18位号码 address 省市县三级地区官方全称:如`北京市`、`台湾省`、`香港特别行政区`、`深圳市`、`黄浦区` birthday 出生日期:如 `2000`、`198801`、`19990101` sex 性别:1为男性,0为女性

func GenerateCode

func GenerateCode(id string) (map[string]string, error)

生成数据

func GenerateLongCode

func GenerateLongCode(id string) (map[string]string, error)

生成长数据

func GenerateShortCode

func GenerateShortCode(id string) (map[string]string, error)

生成短数据

func GeneratorAddressCode

func GeneratorAddressCode(address string) string

生成地址码

func GeneratorBirthdayCode

func GeneratorBirthdayCode(birthday string) string

生成出生日期码

func GeneratorCheckBit

func GeneratorCheckBit(body string) string

生成Bit码

func GeneratorOrderCode

func GeneratorOrderCode(sex int) string

生成顺序码

func GetAddress

func GetAddress(addressCode string, birthdayCode string) string

获取省市区地址码

func GetAddressInfo

func GetAddressInfo(addressCode string, birthdayCode string) map[string]string

检查地址码

func GetChineseZodiac

func GetChineseZodiac(birthdayCode string) string

获取生肖信息

func GetConstellation

func GetConstellation(birthdayCode string) string

获取星座信息

func GetRandAddressCode

func GetRandAddressCode(pattern string) string

获取随机地址码

func IsValid

func IsValid(id string) bool

验证身份证号合法性

func Substr

func Substr(source string, start int, end int) string

Substr 截取字符串

func UpgradeId

func UpgradeId(id string) (string, error)

15位升级18位号码

Types

type IdInfo

type IdInfo struct {
	AddressCode   int
	Abandoned     int
	Address       string
	AddressTree   []string
	Birthday      time.Time
	Constellation string
	ChineseZodiac string
	Sex           int
	Length        int
	CheckBit      string
}

身份证信息

func GetInfo

func GetInfo(id string) (IdInfo, error)

获取身份证信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL