South Korean Resident Registration Number (RRN) Regex for PHP
/^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-([1-4])(\d{6})$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching south korean resident registration number (rrn), 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
// South Korean Resident Registration Number (RRN)
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
define('SOUTH_KOREAN_RESIDENT_REGISTRATION_NUMBER_RRN_PATTERN', '/^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-([1-4])(\d{6})$/');
function validate_south_korean_resident_registration_number_rrn(string $input): bool {
return (bool) preg_match(SOUTH_KOREAN_RESIDENT_REGISTRATION_NUMBER_RRN_PATTERN, $input);
}
// Example
var_dump(validate_south_korean_resident_registration_number_rrn("880101-1234567")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
880101-1234567 | 880101-5234567 |
950615-2345678 | 880001-1234567 |
010115-3456789 | 8801011234567 |
001231-4567890 | 880101-123456 |
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
South Korea's PIPA strictly regulates collection of RRN. Most private sector services are prohibited from collecting RRN and must use i-PIN or other alternatives. Exposure carries significant legal penalties.
Technical Notes
Structure: YYMMDD + gender/birth-year digit + 6 random digits (last is checksum). Gender/century digit: 1=male born 1900s, 2=female born 1900s, 3=male born 2000s, 4=female born 2000s (5-8 used for foreign residents). Checksum via weighted mod 11 algorithm.
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