isVAT.js 493 B

12345678910111213141516
  1. import assertString from './util/assertString';
  2. export var vatMatchers = {
  3. GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,
  4. IT: /^(IT)?[0-9]{11}$/,
  5. NL: /^(NL)?[0-9]{9}B[0-9]{2}$/
  6. };
  7. export default function isVAT(str, countryCode) {
  8. assertString(str);
  9. assertString(countryCode);
  10. if (countryCode in vatMatchers) {
  11. return vatMatchers[countryCode].test(str);
  12. }
  13. throw new Error("Invalid country code: '".concat(countryCode, "'"));
  14. }