se-panfilov / jsvat

Check the validity of the format of an EU VAT number
http://se-panfilov.github.io/jsvat
MIT License
131 stars 34 forks source link

Belgium vat validation issue #104

Open Pouch opened 4 years ago

Pouch commented 4 years ago

There is an issue with the vat validation for Belgium. Actually, vat format is BE0 + 9 numbers.

Using your validator with the example : checkVAT('BE0411905847', [belgium]); // true: accept only Belgium VATs is working but the issue is with this format (without the zero) checkVAT('BE411905847', [belgium]); // return true but should be false

wilgert commented 4 years ago

The code currently prepends the zero to the vat if it is missing: https://github.com/se-panfilov/jsvat/blob/65e584b37798a2b0aeb7bf1d237d743d0b5111a3/src/lib/countries/belgium.ts#L7

Is that wrong?

Pouch commented 4 years ago

Ok that explains why the validator returns true.

Actually, depending on the user's input, the validator is updating it to fit the country's rule. But it implies that the developer must know all formating rules for all countries because the validator will transforms it before validating step. I don't know if it was a request from developers or from you to implement it but is there a way to get a field saying that "the initial input was modified before passing the validation" ?

Because both isValid & isValidFormat fields return true in the actual implementation.