![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)
![NPM](https://nodei.co/npm/jsvat.png?downloads=true&downloadRank=true&stars=true)
jsvat
Demo and Examples
Check the validity of the format of an EU VAT number. No dependencies.
What is it?
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.
What jsvat can?
Several things:
- Say is VAT number valid or not:
jsvat.checkVAT('BG131134023'); //true
jsvat.checkVAT('BG0433170001'); //false
- Check VAT and return country for this VAT:
jsvat.checkVAT('BG13 113 4023', true); //{isValid: true, countries: ['bulgaria']}
jsvat.checkVAT('BG0433170001', true); //{isValid: false, countries: []}
- Validate VAT with only countries from the list:
jsvat.config = {austria: true, belgium: false};
jsvat.checkVAT('ATU5-150-7409'); //true
jsvat.checkVAT('ATU5-804-4146', true); //{isValid: true, countries: ['austria']}
jsvat.checkVAT('BG131134023'); //valid VAT, but result would be 'false'
Installation
- Bower
bower i jsvat --save
- NPM (node.js)
npm i jsvat --save
- Directly download one of the latest releases:
https://github.com/se-panfilov/jsvat/releases
- Just use
jsvat.chcekVat(vat, isDetailed)
from global scope.
If you didn't like global scope - wrap it'
How to use jsvat?
It's simple:
jsvat.chcekVat(vat, isDetailed);
vat
param means VAT number (string
), like "BG0433170001".
vat
can be passed with '-' (BG0-4331-70001
) or ' ' (space, like BG 0433 17 0001
) characters;
isDetailed
param is flag (boolean
, default: false
).
if false
, the result of check will be simple boolean (true or false);
if true
, the result of check will be an Object: {isValid: true, countries: ['austria']}
. Countries is a list of countries which accept passed VAT as valid. Normally there should be only one country, but potentially it's can be more than one.
How does jsvat check the validity?
There is 2-step check:
- 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.
- Some magic mathematical counting;
Here we make some mathematical calculation (different for each country).
After that we may be sure that ATU99999999
and for example ATV66889218
isn't valid, but ATU12011204
is valid.
Source of inspiration:
Based on this great work: http://www.braemoor.co.uk/software/vat.shtml
At the moment the code was in public access without any license information.
I'm totally rewrite all the code.
Browsers Supports
Support all browsers down to IE9 (including IE9).
List of supported Countries:
- Austria
- Belgium
- Bulgaria
- Switzerland
- Cyprus
- Czech Republic
- Germany
- Denmark
- Greece
- Spain
- Europe
- Finland
- France
- United Kingdom
- Croatia
- Hungary
- Ireland
- Italy
- Latvia
- Lithunia
- Luxembourg
- Malta
- Netherlands
- Norway
- Poland
- Portugal
- Romania
- Russia Federation
- Serbia
- Slovenia
- Slovakia republic
- Sweden
LICENSE
MIT: https://github.com/se-panfilov/jsvat/blob/master/LICENSE