stdnum.za.idnr

ID number (South African Identity Document number).

The South African ID number is issued to individuals within South Africa. The number consists of 13 digits and contains information about a person’s date of birth, gender and whether the person is a citizen or permanent resident.

More information:

>>> validate('7503305044089')
'7503305044089'
>>> validate('8503305044089')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> validate('9125568')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> get_gender('7503305044089')
'M'
>>> get_birth_date('7503305044089')
datetime.date(1975, 3, 30)
>>> get_citizenship('7503305044089')
'citizen'
>>> format('750330 5044089')
'750330 5044 08 9'
stdnum.za.idnr.compact(number: str) str

Convert the number to the minimal representation.

This strips the number of any valid separators and removes surrounding whitespace.

stdnum.za.idnr.format(number: str) str

Reformat the number to the standard presentation format.

stdnum.za.idnr.get_birth_date(number: str) date

Split the date parts from the number and return the date of birth.

Since the number only uses two digits for the year, the century may be incorrect.

stdnum.za.idnr.get_citizenship(number: str) str

Get the citizenship status (citizen/resident) from the ID number.

stdnum.za.idnr.get_gender(number: str) str

Get the gender (M/F) from the person’s ID number.

stdnum.za.idnr.is_valid(number: str) bool

Check if the number is a valid South African ID number.

stdnum.za.idnr.validate(number: str) str

Check if the number is a valid South African ID number.

This checks the length, formatting and check digit.