stdnum.es.nie

NIE (Número de Identificación de Extranjero, Spanish foreigner number).

The NIE is an identification number for foreigners. It is a 9 digit number where the first digit is either X, Y or Z and last digit is a checksum letter.

More information:

>>> validate('x-2482300w')
'X2482300W'
>>> validate('x-2482300a')  # invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> validate('X2482300')  # digit missing
Traceback (most recent call last):
    ...
InvalidLength: ...
stdnum.es.nie.calc_check_digit(number)

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

stdnum.es.nie.compact(number)

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

stdnum.es.nie.is_valid(number)

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

stdnum.es.nie.validate(number)

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