Angular-jsvat

Check the validity of the format of an EU VAT number.


Project maintained by se-panfilov Hosted on GitHub Pages — Theme by mattgraham

angular-jsvat

Check the validity of the format of an EU VAT number. No dependencies(except angularjs of course).

There are few valid codes:
  • ATU00000024
  • BE0414445663
  • RS 100 182 160
  • RU-027-4051-582
There are few invalid codes:
  • ATU10223001
  • BE0000200334
  • RO-000-0999-08
  • RU5027187067

What is it?

Angular-js wrapper for jsvat

jsvat is a small library to check validity of European (and few non-eu) VAT number. ( learn more about VAT) jsvat use 2-step check (see below) and didn't make any request for external resources.

Each country has own regexp for VAT number and different math-logic of number calculating.

For more details check jsvat repo.

What angular-jsvat do

  1. Provide JsVatFactory facatory (just an angularjs wrapper for jsvat)

    Just check is VAT number valid or not and which country this VAT is: JsVatFactory.checkVAT('BG131134023'); // {isValid: true, country: 'bulgaria', value: 'BG131134023'}
    JsVatFactory.checkVAT('BG0433170001'); //{isValid: false, country: null, value: 'BG0433170001'}
    JsVatFactory.checkVAT('atu5-150-7409'); //{isValid: true, country: 'austria', value: 'ATU51507409'}
    JsVatFactory.checkVAT('aTU 5 804 4146'); //{isValid: true, country: 'austria', value: 'ATU58044146'}

  2. You can specify list of allowed countries

    JsVatFactory.config = ['austria', 'belgium']; //All countries except 'austria' and 'belgium' would return false
    JsVatFactory.checkVAT('BG131134023'); //valid VAT, but result would be 'false'

Installation

  1. Bower

    bower i angular-jsvat --save

  2. NPM (node.js)

    npm i angular-jsvat --save

  3. Directly download one of the latest releases:

    https://github.com/se-panfilov/angular-jsvat/releases

  4. After that, just include angular-jsvat as a dependency

    angular.module('app', ['angular-jsvat'])

    (no dependencies required, angular-jsvat is standalone app)

How does jsvat check the validity?

It use jsvat) core functionality:

There is 2-step check:

  1. Compare with list of Regexps;

    For example regexp for austria is /^(AT)U(\d{8})$/.

    Looks like ATU99999999 is valid (it's successfied the regexp), but actually it's should be invalid.

  2. Some magic mathematical counting;

    Here we make some mathematical calculation (different for each country). After that we may be sure that ATU99999999and for example ATV66889218 isn't valid, but ATU12011204 is valid.

List of supported Countries:

Browsers Supports

Support all browsers down to IE9 (including IE9).

LICENSE

MIT: https://github.com/se-panfilov/jsvat/blob/master/LICENSE