Referencia Catastral (Spanish real estate property id)

The cadastral reference code is an identifier for real estate in Spain. It is issued by Dirección General del Catastro (General Directorate of Land Registry) of the Ministerio de Hacienda (Tresury Ministry).

It has 20 digits and contains numbers and letters including the Spanish Ñ. The number consists of 14 digits for the parcel, 4 for identifying properties within the parcel and 2 check digits. The parcel digits are structured differently for urban, non-urban or special (infrastructure) cases.

More information:

>>> validate('7837301-VG8173B-0001 TT')  # Lanteira town hall
>>> validate('783301 VG8173B 0001 TT')  # missing digit
Traceback (most recent call last):
InvalidLength: ...
>>> validate('7837301/VG8173B 0001 TT')  # not alphanumeric
Traceback (most recent call last):
InvalidFormat: ...
>>> validate('7837301 VG8173B 0001 NN')  # bad check digits
Traceback (most recent call last):
InvalidChecksum: ...
>>> format('4A08169P03PRAT0001LR')  # BCN Airport
'4A08169 P03PRAT 0001 LR'

Calculate the check digits for the number.

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

Reformat the number to the standard presentation format.

Check if the number is a valid Cadastral Reference.

Check if the number is a valid Cadastral Reference. This checks the length, formatting and check digits.