South Korean Resident Registration Number (RRN) Regex for Java
/^(\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 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
// South Korean Resident Registration Number (RRN)
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
import java.util.regex.Pattern;
public class SouthKoreanResidentRegistrationNumberRrnValidator {
private static final Pattern PATTERN =
Pattern.compile("^(\\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])-([1-4])(\\d{6})$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("880101-1234567")); // 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 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
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