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

Chinese Citizen ID Number (Shenfenzheng) Regex for PHP

/^[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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

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

define('CHINESE_CITIZEN_ID_NUMBER_SHENFENZHENG_PATTERN', '/^[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]$/');

function validate_chinese_citizen_id_number_shenfenzheng(string $input): bool {
    return (bool) preg_match(CHINESE_CITIZEN_ID_NUMBER_SHENFENZHENG_PATTERN, $input);
}

// Example
var_dump(validate_chinese_citizen_id_number_shenfenzheng("110101199003077515")); // bool(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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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