Validate GBVat Number("GB 815382335"); // False is Valid = VAT.
Validate GBVat Number("GB 81538233424242"); // False is Valid = VAT.
Old hand, am I right in saying that the code you provided looks at the format only? To be honest, the customs and excise guide book only provided this - it didn't provide any details on what numerical logic constitutes a valid vat number.
rather than the logic of the numbering to constitute a valid VAT number...? So it might well be that there is no numerical logic (that's the way I understood it) or, if there is a logic then it wasn't included in their handbook (or I completely missed it).
To validate them, we use the VIES API which is provided by the EU: Hotjar currently only accepts intra-Community VAT numbers which are successfully validated by VIES.
The first step is a matter of looping through the characters and maintaining a running total of the numeric value multiplied by the index), in pseudo-code: Now, based on your added code fragment, you probably need to handle both types of VAT number, those with 9 digits and those with 12 digits.To validate a UK VAT number manually you can perform the following exercise: Excluding the first 2 letters, list the numbers vertically and multiply each by a value starting with 8 and ending with 2.Then add up all the sums you have and deduct 97 from the sum until the answer is negative.UK Customs and Excise provide a VAT handbook that issues guidelines on what is a valid VAT number for each of the european states - there might be something on their website.Alternatively, if you're not in the UK I imagine your national customs and excise (or equivalent) will have this info. Incidentally,is there any reason why you don't want to do this at the application tier?
VAT numbers are not randomly or sequentially generated but are based on a formula that can be checked to see if the number is valid.