id-validator/id_validator.go
2021-01-10 13:29:14 +08:00

24 lines
507 B
Go

package id_validator
// 验证身份证号合法性
func IsValid(id string) bool {
if !CheckIdArgument(id) {
return false
}
code := GenerateType(id)
if !CheckAddressCode(code["addressCode"], code["birthdayCode"]) || !CheckBirthdayCode(code["birthdayCode"]) || !CheckOrderCode(code["order"]) {
return false
}
// 15位身份证不含校验码
if code["type"] == "15" {
return true
}
// 验证:校验码
checkBit := GeneratorCheckBit(code["body"])
return code["checkBit"] == checkBit
}