diff --git a/stdnum/kr/rrn.py b/stdnum/kr/rrn.py index 9a8bf8e6..e7a65797 100644 --- a/stdnum/kr/rrn.py +++ b/stdnum/kr/rrn.py @@ -29,11 +29,17 @@ Koreans or the issuing agency for foreigners, followed by two digits for the community center number, one serial number and a check digit. +Numbers given out since 2020-10-05 (to newborns and when a number is +changed) have six random digits after the seventh digit, so for people born +from 2020-09-05 on only the date of birth and the seventh digit can be +checked. + More information: * https://www.law.go.kr/lsSc.do?tabMenuId=tab18&p1=&subMenu=1&nwYn=1§ion=&tabNo=&query=개인정보+보호법 * https://en.wikipedia.org/wiki/Resident_registration_number * https://techscience.org/a/2015092901/ +* https://m.go.seoul.co.kr/news/2019/12/18/20191218014003 >>> validate('971013-9019902') '9710139019902' @@ -99,14 +105,18 @@ def validate(number: str, allow_future: bool = True) -> str: raise InvalidFormat() if len(number) != 13: raise InvalidLength() - get_birth_date(number, allow_future) - place_of_birth = int(number[7:9]) - if place_of_birth > 96: - raise InvalidComponent() - # We cannot check the community center (CC), any information on - # valid/invalid CC digits is welcome. - if number[-1] != calc_check_digit(number[:-1]): - raise InvalidChecksum() + date_of_birth = get_birth_date(number, allow_future) + # Numbers given out since 2020-10-05 have six random digits after the + # seventh digit. A birth has to be reported within a month, so anyone + # born from 2020-09-05 on can have such a number. + if date_of_birth < datetime.date(2020, 9, 5): + place_of_birth = int(number[7:9]) + if place_of_birth > 96: + raise InvalidComponent() + # We cannot check the community center (CC), any information on + # valid/invalid CC digits is welcome. + if number[-1] != calc_check_digit(number[:-1]): + raise InvalidChecksum() return number diff --git a/tests/test_kr_rrn.doctest b/tests/test_kr_rrn.doctest index bebd39e8..6550c883 100644 --- a/tests/test_kr_rrn.doctest +++ b/tests/test_kr_rrn.doctest @@ -74,6 +74,24 @@ Traceback (most recent call last): InvalidComponent: ... +Numbers given out since 2020-10-05 have six random digits after the seventh +digit, so there is no place of birth or check digit to validate for people +born after the change. The date of birth is still checked. + +>>> rrn.validate('210503-3999990') # born 2021-05-03 +'2105033999990' +>>> rrn.validate('200905-4123456') # born 2020-09-05, reported after 2020-10-05 +'2009054123456' +>>> rrn.validate('200904-4123456') # born 2020-09-04, reported before the change +Traceback (most recent call last): + ... +InvalidChecksum: ... +>>> rrn.validate('210230-3123456') # invalid date of birth 2021-02-30 +Traceback (most recent call last): + ... +InvalidComponent: ... + + These have been randomly `generated online `_ and should all be valid numbers.