stdnum.mx.rfc

RFC (Registro Federal de Contribuyentes, Mexican tax number).

This number is used to identify individuals and companies for tax purposes.

The company number is 12 digits where the first 3 letters or digits are derived from the name of the company, the following 6 contain the date of incorporation, followed by 3 check digits.

Personal numbers consist of 13 digits where the first 4 characters from the person’s name, followed by their birth date and 3 check digits.

The first two check digits are calculated based on the person’s or company’s full name. The last check digit is calculated over all the preceding digits in the number. However, it seems a lot of numbers (estimated at around 1.5% of all numbers) are in use with invalid check digits so this test is disabled by default.

More information:

An online validation service is available at:

>>> validate('GODE 561231 GR8')  # personal number
'GODE561231GR8'
>>> validate('MAB-930714-8T4')  # company number
'MAB9307148T4'
>>> validate('COMG-600703')  # personal number without serial
'COMG600703'
>>> validate('VACE-460910-SX6')
'VACE460910SX6'
>>> validate('VACE-460910-SX6', validate_check_digits=True)
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> format('GODE561231GR8')
'GODE 561231 GR8'
stdnum.mx.rfc.calc_check_digit(number)

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

stdnum.mx.rfc.compact(number)

Convert the number to the minimal representation. This strips surrounding whitespace and separation dash.

stdnum.mx.rfc.format(number, separator=' ')

Reformat the number to the standard presentation format.

stdnum.mx.rfc.is_valid(number, validate_check_digits=False)

Check if the number provided is a valid RFC.

stdnum.mx.rfc.validate(number, validate_check_digits=False)

Check if the number is a valid RFC.