NIE (Número de Identificación de Extranjeros, 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.
>>> 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: ...
Traceback (most recent call last):
...
InvalidLength: ...
Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.
Checks to see if the number provided is a valid NIE. This checks the length, formatting and check digit.