Cn resident id parse
cn-resident-id-parse · version 1.0.0 · Identifiers & check digits · free, no key needed
Parse an 18-digit (or legacy 15-digit) Chinese resident ID: region code, birth date, sex and GB 11643-1999 check digit.
Use when you need to: parse a chinese id card number · validate a china resident identity card number · check digit for a PRC id number.
Decide before calling
Read the versioned contract and the supported scope below. Reuse cn-resident-id-parse@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use cn-resident-id-parse@1.0.0 for parse a chinese id card number. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- parse a chinese id card number
- validate a china resident identity card number
- check digit for a PRC id number
- extract birth date from chinese national id
- convert 15 digit chinese id to 18 digit
- GB 11643 id number checksum
- 身份证号码校验
Not supported
- looking up the administrative region name for the 6-digit region code (no GB/T 2260 lookup or region-name data)
- validating a national ID from any country other than China
- accepting a lowercase x in the 18th position or any whitespace/hyphen formatting
Behavior
- id must be exactly 15 ASCII digits (legacy form) or exactly 17 ASCII digits followed by a digit or uppercase X (18-digit form); anything else throws invalid_input. No trimming, case folding or separators.
- 15-digit input is upgraded to 17 digits by inserting '19' after the 6-digit region code (this tool assumes the 1900s century, since the 15-digit form predates the 2000s); 18-digit input's first 17 characters are used as-is.
- check_digit is always the GB 11643-1999 weighted mod-11 computation over the 17-digit payload (weights 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2, remainder table 0..10 -> 1,0,X,9,8,7,6,5,4,3,2), independent of whether it matches the supplied 18th character.
- id18 preserves the original 18th character when one was supplied (even when it disagrees with check_digit); for 15-digit input, id18 uses the freshly computed check_digit, so a 15-digit input can never produce checksum_mismatch.
- birth_date is validated as a real proleptic Gregorian calendar date using the encoded 4-digit year (leap years: divisible by 4 and (not divisible by 100 or divisible by 400)); an invalid date reports birth_date: null and takes precedence over a checksum mismatch.
- sex is derived from the 17th character of the 17-digit payload (the last digit of the 3-digit sequence code): odd is male, even is female; this is always computed, regardless of date or checksum validity.
- region_code is the payload's first 6 characters returned unchanged; no administrative-division lookup is performed.
- Pure integer arithmetic and a fixed calendar rule; no locale, clock, or randomness; identical output across runs for the same input.
Input
id(string, required): min length 15; max length 18; pattern^(\d{15}|\d{17}[0-9X])$
Output
valid(boolean, required)reason(one of null, "invalid_birth_date", "checksum_mismatch", required)region_code(string, required): pattern^\d{6}$birth_date(string or null, required): pattern^\d{4}-\d{2}-\d{2}$sex(one of "male", "female", required)check_digit(string, required): pattern^[0-9X]$id18(string, required): pattern^\d{17}[0-9X]$
Limits
- max input bytes: 18
Example
Request input:
{
"id": "11010519491231002X"
}
Response:
{
"result": {
"valid": true,
"reason": null,
"region_code": "110105",
"birth_date": "1949-12-31",
"sex": "female",
"check_digit": "X",
"id18": "11010519491231002X"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "cn-resident-id-parse",
"version": "1.0.0",
"input": {
"id": "11010519491231002X"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/cn-resident-id-parse/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"id":"11010519491231002X"}'
The machine-readable contract is at /v1/tools/cn-resident-id-parse/versions/1.0.0.
CLI
node cli.mjs run cn-resident-id-parse 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Se personnummer parse: Parse a Swedish personnummer/samordningsnummer: resolve its century, return birth date, sex and Luhn validity.
- Isin validate: Validate a 12-character ISIN's ISO 6166 Luhn check digit and parse its country prefix, NSIN and NSIN scheme.
- Cusip validate: Validate a 9-character CUSIP's Modulus 10 Double Add Double check digit and parse its issuer, issue and PPN marker.
- Isin compute from nsin: Build a 12-character ISIN from a country prefix and a CUSIP/SEDOL national number, computing its Luhn check digit.
- Ismn validate: Validate an ISMN's EAN mod 10 check digit in M-form or 979-0 form and return the canonical 13-digit form.
- Issn validate: Validate an 8-digit ISSN's mod 11 check digit (X allowed) and compute its 977-prefixed EAN-13 barcode form.