REGEXVAULTv2.0
Identity & PII/National Identity Numbers
Verified Safe

Chinese Citizen ID Number (Shenfenzheng) Regex for Java

/^[1-8][0-9]{5}((?:19|20)[0-9]{2})(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9X]$/i

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching chinese citizen id number (shenfenzheng), ported and verified for Java. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

Java
// Chinese Citizen ID Number (Shenfenzheng)
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers

import java.util.regex.Pattern;

public class ChineseCitizenIdNumberShenfenzhengValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^[1-8][0-9]{5}((?:19|20)[0-9]{2})(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9X]$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("110101199003077515")); // true
    }
}

Test Cases

Matches (Valid)
Rejects (Invalid)
11010119900307751501010119900307771X
440301200001010002110101199013077515
31010519900307771X1101011990030777151

When to use this pattern

This pattern is drawn from the Identity & PII > National Identity Numbers category and carries a ReDoS-safe certification. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

The sequence number (positions 15-17) encodes gender: odd=male, even=female. Region codes starting with 9 are used for special purposes (overseas Chinese, some SAR contexts). X as check character is uppercase only in official use.

Technical Notes

Structure: 6-digit region code (first digit 1-8) + 8-digit birthdate (YYYYMMDD) + 3-digit sequence + 1 check character. Check character X represents 10. Region code first digit 1-8 corresponds to Chinese provinces (9 not currently used for mainland). Checksum uses ISO 7064 MOD 11-2.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern