South Korean Resident Registration Number (RRN) Regex for Go
/^(\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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// South Korean Resident Registration Number (RRN)
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers
package validation
import "regexp"
var southKoreanResidentRegistrationNumberRrnRe = regexp.MustCompile(`^(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-([1-4])(\d{6})$`)
func ValidateSouthKoreanResidentRegistrationNumberRrn(s string) bool {
return southKoreanResidentRegistrationNumberRrnRe.MatchString(s)
}
// Example
// fmt.Println(ValidateSouthKoreanResidentRegistrationNumberRrn("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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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