VAT (United Kingdom (and Isle of Man) VAT registration number).

The VAT number can either be a 9-digit standard number, a 12-digit standard number followed by a 3-digit branch identifier, a 5-digit number for government departments (first two digits are GD) or a 5-digit number for health authorities (first two digits are HA). The 9-digit variants use a weighted checksum.

>>> validate('GB 980 7806 84')
>>> validate('802311781')  # invalid check digit
Traceback (most recent call last):
InvalidChecksum: ...
>>> format('980780684')
'980 7806 84'

Calculate the checksum. The checksum is only used for the 9 digits of the number and the result can either be 0 or 42.

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 VAT number.

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