peteromallet / Advisable

3 stars 0 forks source link

Vat number #2141

Closed thomascullen closed 2 years ago

thomascullen commented 2 years ago

Decided to go some what simple on this. The two packages we found for VAT validation are jsvat and validate-vat. I don't really like either of these because one seems outdated with a decent amount of open issues and the other is dependent on a non public API and has some CORS issues.

What I have done is just added a default regex pattern for starting with country code and between 8 and 12 alphanumeric chars. I've then included specific regex patterns for Switzerland and Norway to handle those edge cases. This definitely isn't perfect and doesn't guarantee that the VAT number is actually valid but the main goal here is just to ensure that the vat numbers begin with the correct country code which is what we use to determine whether or not to apply VAT and this should do the job for that without adding more dependencies 🤷 . We do actually validate the VAT number with Stripe. However, this happens after we have already saved the change to our DB so even though they are show the error message, they could click away without changing it.

image

Reviewer Checklist