Skip to content

fix(kr/rrn): skip the check digit for alien registration numbers - #256

Merged
koblas merged 1 commit into
mainfrom
fix/kr-rrn-arn-checksum
Nov 11, 2026
Merged

koblas merged 1 commit into
mainfrom
fix/kr-rrn-arn-checksum

Conversation

@koblas

@koblas koblas commented Nov 11, 2026

Copy link
Copy Markdown
Owner

kr/rrn accepts alien registration numbers (외국인등록번호, 7th digit 5–8) but checked them with the RRN check digit formula. That formula has no source for ARNs, so valid numbers could be rejected. This change checks only the length, digits and birth date for them, the same as for numbers issued since October 2020.

Refs #3

Evidence

  • The Enforcement Decree of the Immigration Act, Article 40-3, defines the ARN as 13 digits showing birth date, sex and registering office, and leaves the detailed scheme to the Minister of Justice (법무부장관이 정한다): https://www.law.go.kr/LSW//lumLsLinkPop.do?lspttninfSeq=82633&chrClsCd=010202
  • Since 2012-06-01 the 12th digit (구분) was dropped and the serial grew to 3 digits (Korean embassy notice): https://overseas.mofa.go.kr/hn-ko/brd/m_6364/view.do?seq=918639
  • No official source gives a check digit formula. python-stdnum applies the RRN formula; Microsoft Presidio and several blogs use (13 - sum % 11) % 10, which is always the RRN value + 2. The two can't both be right, and neither cites a source.

Comparison with python-stdnum 2.2

Mutation diff over 20,500 inputs (the spec's valid numbers with every 7th and last digit, plus 20,000 random dated numbers), comparing this branch with main: the only change is 4,398 numbers now accepted that main and python-stdnum reject. All of them have a 7th digit of 5–8 and a birth year before 2020. Nothing else changed. This is a deliberate difference from python-stdnum, to be noted on #91.

Not verified

  • The Minister of Justice rule that the decree delegates to: no public copy found.
  • 7th digit 5/7 = male, 6/8 = female comes from a 2023 MOJ press release, found only on an SNU mirror. The 5/6 → 1900s, 7/8 → 2000s mapping is inferred from the RRN scheme.
  • Whether the October 2020 randomisation also applies to ARNs (they fall under the Immigration Act, not the Resident Registration Act). Irrelevant now that the check digit is skipped for all ARNs.
  • No real ARNs were used; the test values are made up.
  • 7th digits 9 and 0 (1800s) are still checked as RRNs; there is no source that foreigners use them.

Numbers with century/gender digit 5-8 are alien registration numbers
(외국인등록번호). Their check digit formula isn't published: the
Enforcement Decree of the Immigration Act (Article 40-3) leaves the
scheme to the Minister of Justice. python-stdnum applies the RRN formula,
other validators add 2 to it, and neither cites a source, so valid
numbers could be rejected. Check only the length, digits and birth date,
as for numbers issued since 2020.
@koblas koblas mentioned this pull request Nov 11, 2026
2 of 32 tasks
@koblas
koblas merged commit 791779a into main Nov 11, 2026
10 checks passed
@koblas
koblas deleted the fix/kr-rrn-arn-checksum branch November 11, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant