card

package
v0.0.0-...-b6f14a9 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 4 Imported by: 0

README

China identify card utils

Usage

i, err := card.New("44522119830409724x")
i.Validate()
i.CalcAge()
i.GetAddress()

Documentation

Index

Constants

View Source
const (
	MaxAge = 256
)

The up bound of person age.

Variables

View Source
var (
	ErrInvalidFormat   = errors.New("invalid format of China identity card")
	ErrInvalidLength   = errors.New("invalid length of China identity card")
	ErrInvalidAge      = errors.New("invalid age(between 0-120)")
	ErrInvalidCheckSum = errors.New("invalid checksum")
)

Define errors

View Source
var (
	IdentityWeightFactor = []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
	IdentifyChecksums    = []byte{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}

	IdentityCardProvince = map[string]string{
		"11": "北京", "12": "天津", "13": "河北", "14": "山西", "15": "内蒙古",
		"21": "辽宁", "22": "吉林", "23": "黑龙江", "31": "上海", "32": "江苏",
		"33": "浙江", "34": "安徽", "35": "福建", "36": "江西", "37": "山东",
		"41": "河南", "42": "湖北", "43": "湖南", "44": "广东", "45": "广西", "46": "海南",
		"50": "重庆", "51": "四川", "52": "贵州", "53": "云南", "54": "西藏",
		"61": "陕西", "62": "甘肃", "63": "青海", "64": "宁夏", "65": "新疆",
		"71": "台湾", "81": "香港", "82": "澳门", "91": "国外",
	}

	IdentityAddress = map[int]string{}/* 3512 elements not displayed */

)

Functions

This section is empty.

Types

type IdentityCard

type IdentityCard struct {
	Original string
	Address  string
	Birthday string
	Order    string
	Checksum byte
}

IdentityCard represents China identity card.

func New

func New(s string) (*IdentityCard, error)

New initializes the IdentityCard with given string.

func (*IdentityCard) CalcAge

func (i *IdentityCard) CalcAge(t *time.Time) (age int)

CalcAge calculates the real age.

func (*IdentityCard) CalcChecksum

func (i *IdentityCard) CalcChecksum() byte

CalcChecksum calculate the checksum number.

func (*IdentityCard) GetAddress

func (i *IdentityCard) GetAddress() string

GetAddress get address name.

func (*IdentityCard) Validate

func (i *IdentityCard) Validate() (ok bool, err error)

Validate checks the card number.

func (*IdentityCard) ValidateAge

func (i *IdentityCard) ValidateAge() (ok bool, err error)

ValidateAge checks the age.

func (*IdentityCard) ValidateChecksum

func (i *IdentityCard) ValidateChecksum() (bool, error)

ValidateChecksum checks the checksum number.

func (*IdentityCard) ValidateProvince

func (i *IdentityCard) ValidateProvince() (ok bool, err error)

ValidateProvince checks the province.

Jump to

Keyboard shortcuts

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