stdnum.gb.vat

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')
'980780684'
>>> validate('802311781')  # invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> format('980780684')
'980 7806 84'
stdnum.gb.vat.checksum(number)

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

stdnum.gb.vat.compact(number)

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

stdnum.gb.vat.format(number)

Reformat the number to the standard presentation format.

stdnum.gb.vat.is_valid(number)

Check if the number is a valid VAT number.

stdnum.gb.vat.validate(number)

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