Skip to content

Latest commit

 

History

History
86 lines (62 loc) · 2.9 KB

README-en.md

File metadata and controls

86 lines (62 loc) · 2.9 KB

Legality check of "China Citizen ID Card Number" and "China Unified Social Credit Code for Legal Persons and Other Organizations"

License: MIT

中文 | English

A go package for verify the ID card number and the unified social credit code of legal persons and other organizations.

Calculation rules refer to national standard documents:

Note: Due to the earlier implementation of the “Unified Social Credit Code for Legal Persons and Other Organizations” in some pilot areas of China, some code may not meet national standards, But they are all rightful code and should be handled separately. For example:

福建恒跃柳工机械销售有限公司: 91350100M0001TGQXM The calculated check digit is 1 and M does not match

厦门云上晴空航空科技有限公司: 91350211M0000XUF46 The calculated check digit is R and 6 does not match.

厦门黑脉网络科技有限公司: 91350203M0001FUE2P The calculated check digit is J and P dos not match.

How to use

go get github.com/bluesky335/IDCheck
  • Unified social credit code for legal persons and other organizations
    import "github.com/bluesky335/IDCheck/USCI"
  
    var usci = USCI.New("91350100M000100Y43")
    if usci.IsValid() {
        fmt.Printf("✅\n")
    } else {
        fmt.Printf("❌\n")
    }
  • identification number
    import "github.com/bluesky335/IDCheck/IdNumber"

    var id = IdNumber.New("11010519491231002X")
    if id.IsValid() {
        fmt.Printf("%s -> %s\n", id, "✅")
    } else {
        fmt.Printf("%s -> %s\n", id, "❌")
    }
    
    var birthday = id.GetBirthday()
    if birthday != nil {
        fmt.Printf("Birthday:%s-%s-%s\n", birthday.Year, birthday.Month, birthday.Day)
    } else {
        // invalid ID card number
    }
    
    var gender = id.GetGender()
    if gender != -1 {
        genderMap := map[Gender]string{
            Female: "Female",
            Male:   "Male",
        }
        fmt.Printf("Gender:%s\n", genderMap[gender])
    } else {
        // invalid ID card number
    }
    
    // Generate a random ID number that conforms to the verification rules. Although it complies with the verification rules, it does not necessarily exist.
    randomIDCard := IdNumber.Random()
    fmt.Printf("random ID number:%s\n", randomIDCard)
     

Swift version

IDCard

JavaScript version

ChrisDowney1996 validators