stdnum.es.dni

DNI (Documento Nacional de Identidad, Spanish personal identity codes).

The DNI is a 9 digit number used to identify Spanish citizens. The last digit is a checksum letter.

Foreign nationals, since 2010 are issued an NIE (Número de Identificación de Extranjeros, Foreigner’s Identity Number) instead.

>>> validate('54362315-K')
'54362315K'
>>> validate('54362315Z')  # invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> validate('54362315')  # digit missing
Traceback (most recent call last):
    ...
InvalidLength: ...
stdnum.es.dni.calc_check_digit(number)

Calculate the check digit. The number passed should not have the check digit included.

stdnum.es.dni.compact(number)

Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.es.dni.is_valid(number)

Check if the number provided is a valid DNI number. This checks the length, formatting and check digit.

stdnum.es.dni.validate(number)

Check if the number provided is a valid DNI number. This checks the length, formatting and check digit.