# 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:

- https://www.infomex.org.mx/jspsi/documentos/2005/seguimiento/06101/0610100162005_065.doc

- https://es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)

An online validation service is available at:

- https://portalsat.plataforma.sat.gob.mx/ConsultaRFC/

    >>> 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: str) → str

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

stdnum.mx.rfc.compact(number: str) → str

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

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

  Reformat the number to the standard presentation format.

stdnum.mx.rfc.is_valid(number: str, validate_check_digits: bool = False) → bool

  Check if the number provided is a valid RFC.

stdnum.mx.rfc.validate(number: str, validate_check_digits: bool = False) → str

  Check if the number is a valid RFC.