stdnum.cr.cr

CR (Cédula de Residencia, Costa Rica foreigners ID number).

The Cédula de Residencia (CR), also know as DIMEX or Documento de Identificación Migratorio para Extranjeros, is an identifier of foreigners in Costa Rica.

This number consists of 11 or 12 digits in the form 1NNN-CC…C-EE…E where NNN represents the code of the country the foreigner comes from as specified by Costa Rica’s Dirección General de Migración y Extranjería, CC…C is a sequence telling how many Cédula de Residencia have been issued in total and EE…E is a sequence telling how many Cédula de Residencia have been issued for that particular foreign country.

More information:

>>> validate('155812994816')
'155812994816'
>>> validate('30123456789')
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> validate('12345678')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> format('122200569906')
'122200569906'
stdnum.cr.cr.compact(number)

Convert the number to the minimal representation.

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

stdnum.cr.cr.format(number)

Reformat the number to the standard presentation format.

stdnum.cr.cr.is_valid(number)

Check if the number is a valid Costa Rica CR number.

stdnum.cr.cr.validate(number)

Check if the number is a valid Costa Rica CR number.

This checks the length and formatting.