South Korean Resident Registration Number (RRN) Regex for Python
/^(\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 Python. 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 Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.
Python Implementation
# South Korean Resident Registration Number (RRN)
# ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
import re
south_korean_resident_registration_number_rrn_pattern = re.compile(r'^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-([1-4])(\d{6})$')
def validate_south_korean_resident_registration_number_rrn(value: str) -> bool:
return bool(south_korean_resident_registration_number_rrn_pattern.fullmatch(value))
# Example
print(validate_south_korean_resident_registration_number_rrn("880101-1234567")) # TrueTest 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 Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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