stdnum.sv.nit

NIT (Número de Identificación Tributaria, El Salvador tax number).

This number consists of 14 digits, usually separated into four groups using hyphens to make it easier to read, like XXXX-XXXXXX-XXX-X.

The first four digits indicate the code for the municipality of birth for natural persons or the municipality of stablishment for juridical persons. NIT for El Salvador nationals begins with either 0 or 1, and for foreigners it begins with 9.

The following six digits indicate the date of birth for the natural person, or the stablishment date for the juridical person, using the format DDMMYY, where DD is the day, MM is the month, and YY is the year. For example XXXX-051180-XXX-X is (November 5 1980)

The next 3 digits are a sequential number.

The last digit is the check digit, which is used to verify the number was correctly typed.

More information:

>>> validate('0614-050707-104-8')
'06140507071048'
>>> validate('SV 0614-050707-104-8')
'06140507071048'
>>> validate('0614-050707-104-0')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> validate('12345678')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> format('06140507071048')
'0614-050707-104-8'
stdnum.sv.nit.calc_check_digit(number: str) str

Calculate the check digit.

stdnum.sv.nit.compact(number: str) str

Convert the number to the minimal representation.

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

stdnum.sv.nit.format(number: str) str

Reformat the number to the standard presentation format.

stdnum.sv.nit.is_valid(number: str) bool

Check if the number is a valid El Salvador NIT number.

stdnum.sv.nit.validate(number: str) str

Check if the number is a valid El Salvador NIT number.

This checks the length, formatting and check digit.