stdnum.es.cif

CIF (Código de Identificación Fiscal, Spanish company tax number).

The CIF is a tax identification number for legal entities. It has 9 digits where the first digit is a letter (denoting the type of entity) and the last is a check digit (which may also be a letter).

More information

>>> validate('J99216582')
'J99216582'
>>> validate('J99216583')  # invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> validate('J992165831')  # too long
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> validate('M-1234567-L')  # valid NIF but not valid CIF
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> validate('O-1234567-L')  # invalid first character
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> split('A13 585 625')
('A', '13', '58562', '5')
stdnum.es.cif.compact(number)

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

stdnum.es.cif.is_valid(number)

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

stdnum.es.cif.split(number)

Split the provided number into a letter to define the type of organisation, two digits that specify a province, a 5 digit sequence number within the province and a check digit.

stdnum.es.cif.validate(number)

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