PVN (Pievienotās vērtības nodokļa, Latvian VAT number).

The PVN is a 11-digit number that can either be a reference to a legal entity (in which case the first digit > 3) or a natural person (in which case it should be the same as the personal code (personas kods)). Personal codes start with 6 digits to denote the birth date in the form ddmmyy.

>>> validate('LV 4000 3521 600')
>>> validate('40003521601')  # invalid check digit
Traceback (most recent call last):
InvalidChecksum: ...
>>> validate('161175-19997')  # personal code
>>> validate('161375-19997')  # invalid date
Traceback (most recent call last):
InvalidComponent: ...

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

Calculate the checksum for legal entities.

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

Split the date parts from the number and return the birth date.

Check if the number is a valid VAT number.

Check if the number is a valid VAT number. This checks the length, formatting and check digit.