Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsvat

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsvat - npm Package Compare versions

Comparing version 0.4.8 to 0.6.0

2

bower.json
{
"name": "jsvat",
"version": "0.4.7",
"version": "0.6.0",
"description": "Check the validity of the format of an EU VAT number",

@@ -5,0 +5,0 @@ "main": "./dist/jsvat.js",

var jsvat = (function () {
'use strict';
'use strict';
var _REGEXP_LIST = {
austria: /^(AT)U(\d{8})$/,
belgium: /^(BE)(0?\d{9})$/,
bulgaria: /^(BG)(\d{9,10})$/,
switzerland: /^(CHE)(\d{9})(MWST)?$/,
cyprus: /^(CY)([0-59]\d{7}[A-Z])$/,
czech_republic: /^(CZ)(\d{8,10})(\d{3})?$/,
germany: /^(DE)([1-9]\d{8})$/,
denmark: /^(DK)(\d{8})$/,
estonia: /^(EE)(10\d{7})$/,
greece: /^(EL)(\d{9})$/,
spain: [
/^(ES)([A-Z]\d{8})$/,
/^(ES)([A-HN-SW]\d{7}[A-J])$/,
/^(ES)([0-9YZ]\d{7}[A-Z])$/,
/^(ES)([KLMX]\d{7}[A-Z])$/
],
europe: /^(EU)(\d{9})$/,
finland: /^(FI)(\d{8})$/,
france: [
/^(FR)(\d{11})$/,
/^(FR)([A-HJ-NP-Z]\d{10})$/,
/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,
/^(FR)([A-HJ-NP-Z]{2}\d{9})$/
],
united_kingdom: [
/^(GB)?(\d{9})$/,
/^(GB)?(\d{12})$/,
/^(GB)?(GD\d{3})$/,
/^(GB)?(HA\d{3})$/
],
croatia: /^(HR)(\d{11})$/,
hungary: /^(HU)(\d{8})$/,
ireland: [
/^(IE)(\d{7}[A-W])$/,
/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,
/^(IE)(\d{7}[A-W][AH])$/
],
italy: /^(IT)(\d{11})$/,
latvia: /^(LV)(\d{11})$/,
lithunia: /^(LT)(\d{9}|\d{12})$/,
luxembourg: /^(LU)(\d{8})$/,
malta: /^(MT)([1-9]\d{7})$/,
netherlands: /^(NL)(\d{9})B\d{2}$/,
norway: /^(NO)(\d{9})$/,
poland: /^(PL)(\d{10})$/,
portugal: /^(PT)(\d{9})$/,
romania: /^(RO)([1-9]\d{1,9})$/,
russia: /^(RU)(\d{10}|\d{12})$/,
serbia: /^(RS)(\d{9})$/,
slovenia: /^(SI)([1-9]\d{7})$/,
slovakia_republic: /^(SK)([1-9]\d[2346-9]\d{7})$/,
sweden: /^(SE)(\d{10}01)$/
};
var CONDITIONS = {
austria: {
multipliers: [1, 2, 1, 2, 1, 2, 1],
regex: /^(AT)U(\d{8})$/
},
belgium: {
regex: /^(BE)(0?\d{9})$/
},
bulgaria: {
multipliers: {
physical: [2, 4, 8, 5, 10, 9, 7, 3, 6],
foreigner: [21, 19, 17, 13, 11, 9, 7, 3, 1],
miscellaneous: [4, 3, 2, 7, 6, 5, 4, 3, 2]
},
regex: /^(BG)(\d{9,10})$/
},
switzerland: {
multipliers: [5, 4, 3, 2, 7, 6, 5, 4],
regex: /^(CHE)(\d{9})(MWST)?$/
},
cyprus: {
regex: /^(CY)([0-59]\d{7}[A-Z])$/
},
czech_republic: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
lookup: [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10],
regex: /^(CZ)(\d{8,10})(\d{3})?$/,
additional: [
/^\d{8}$/,
/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/,
/^6\d{8}$/,
/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/
]
},
germany: {
regex: /^(DE)([1-9]\d{8})$/
},
denmark: {
multipliers: [2, 7, 6, 5, 4, 3, 2, 1],
regex: /^(DK)(\d{8})$/
},
estonia: {
multipliers: [3, 7, 1, 3, 7, 1, 3, 7],
regex: /^(EE)(10\d{7})$/
},
greece: {
multipliers: [256, 128, 64, 32, 16, 8, 4, 2],
regex: /^(EL)(\d{9})$/
},
spain: {
multipliers: [2, 1, 2, 1, 2, 1, 2],
regex: [
/^(ES)([A-Z]\d{8})$/,
/^(ES)([A-HN-SW]\d{7}[A-J])$/,
/^(ES)([0-9YZ]\d{7}[A-Z])$/,
/^(ES)([KLMX]\d{7}[A-Z])$/
],
additional: [
/^[A-H|J|U|V]\d{8}$/,
/^[A-H|N-S|W]\d{7}[A-J]$/,
/^[0-9|Y|Z]\d{7}[A-Z]$/,
/^[K|L|M|X]\d{7}[A-Z]$/
]
},
europe: {
regex: /^(EU)(\d{9})$/
},
finland: {
multipliers: [7, 9, 10, 5, 8, 4, 2],
regex: /^(FI)(\d{8})$/
},
france: {
regex: [
/^(FR)(\d{11})$/,
/^(FR)([A-HJ-NP-Z]\d{10})$/,
/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,
/^(FR)([A-HJ-NP-Z]{2}\d{9})$/
]
function _validateRegexp(vat, regexp) {
return regexp.test(vat);
}
},
united_kingdom: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [
/^(GB)?(\d{9})$/,
/^(GB)?(\d{12})$/,
/^(GB)?(GD\d{3})$/,
/^(GB)?(HA\d{3})$/
]
function _validateRules(vat, regexp, countryName) {
var parsedNum = regexp.exec(vat);
},
croatia: {
regex: /^(HR)(\d{11})$/
},
hungary: {
multipliers: [9, 7, 3, 1, 9, 7, 3],
regex: /^(HU)(\d{8})$/
},
ireland: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [
/^(IE)(\d{7}[A-W])$/,
/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,
/^(IE)(\d{7}[A-W][AH])$/
]
//var code = parsedNum[1];
var number = parsedNum[2];
//if (!code || code.length === 0) code = 'GB';
return _checks[countryName](number);
},
italy: {
multipliers: [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],
regex: /^(IT)(\d{11})$/
},
latvia: {
multipliers: [9, 1, 4, 8, 3, 10, 2, 5, 7, 6],
regex: /^(LV)(\d{11})$/
},
lithunia: {
multipliers: {
short: [3, 4, 5, 6, 7, 8, 9, 1],
med: [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2],
alt: [3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4]
},
regex: /^(LT)(\d{9}|\d{12})$/
},
luxembourg: {
regex: /^(LU)(\d{8})$/
},
malta: {
multipliers: [3, 4, 6, 7, 8, 9],
regex: /^(MT)([1-9]\d{7})$/
},
netherlands: {
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: /^(NL)(\d{9})B\d{2}$/
},
norway: {
multipliers: [3, 2, 7, 6, 5, 4, 3, 2],
regex: /^(NO)(\d{9})$/
},
poland: {
multipliers: [6, 5, 7, 2, 3, 4, 5, 6, 7],
regex: /^(PL)(\d{10})$/
},
portugal: {
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: /^(PT)(\d{9})$/
},
romania: {
multipliers: [7, 5, 3, 2, 1, 7, 5, 3, 2],
regex: /^(RO)([1-9]\d{1,9})$/
},
russia: {
multipliers: {
m_1: [2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
m_2: [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
m_3: [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0]
},
regex: /^(RU)(\d{10}|\d{12})$/
},
serbia: {
regex: /^(RS)(\d{9})$/
},
slovenia: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: /^(SI)([1-9]\d{7})$/
},
slovakia_republic: {
regex: /^(SK)([1-9]\d[2346-9]\d{7})$/
},
sweden: {
regex: /^(SE)(\d{10}01)$/
}
};
function _validate(vat, regexp, countryName) {
var result = false;
if (_validateRegexp(vat, regexp)) {
result = _validateRules(vat, regexp, countryName);
}
return result;
}
function _validateRegex(vat, regex) {
return regex.test(vat);
}
var exports = {
checkVAT: function (vat) {
if (!vat) return false;
vat = vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
function _validateRules(vat, regex, countryName) {
var parsedNum = regex.exec(vat);
for (var countryName in _REGEXP_LIST) {
if (_REGEXP_LIST.hasOwnProperty(countryName)) {
var regexp = _REGEXP_LIST[countryName];
//var code = parsedNum[1];
var number = parsedNum[2];
//if (!code || code.length === 0) code = 'GB';
//TODO (S.Panfilov) this is not cross-browser check
if (Array.isArray(regexp)) {
for (var i = 0; i < regexp.length; i++) {
if (_validate(vat, regexp[i], countryName)) return true;
}
} else {
if (_validate(vat, regexp, countryName)) return true;
}
}
}
return false;
return _checks[countryName](number, countryName);
}
}
};
function _validate(vat, regex, countryName) {
var result = false;
if (_validateRegex(vat, regex)) {
result = _validateRules(vat, regex, countryName);
}
return result;
}
var _checks = {
austria: function (vat) {
var total = 0;
var multipliers = [1, 2, 1, 2, 1, 2, 1];
var temp;
var expect;
var exports = {
checkVAT: function (vat) {
if (!vat) return false;
vat = vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
for (var i = 0; i < 7; i++) {
temp = vat.charAt(i) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
for (var countryName in CONDITIONS) {
if (CONDITIONS.hasOwnProperty(countryName)) {
var regex = CONDITIONS[countryName].regex;
total = 10 - (total + 4) % 10;
if (total === 10) total = 0;
expect = +vat.slice(7, 8);
return total === expect;
},
belgium: function (vat) {
var expect;
var check;
if (vat.length === 9) vat = "0" + vat;
if (+vat.slice(1, 2) === 0) return false;
check = (97 - +vat.slice(0, 8) % 97);
expect = +vat.slice(8, 10);
return check === expect;
},
bulgaria: function (vat) {
var expect;
var multipliers;
var temp;
var total;
var checkNineLengthVat = function () {
temp = 0;
for (var i = 0; i < 8; i++) {
temp += +vat.charAt(i) * (i + 1);
}
total = temp % 11;
if (total !== 10) {
expect = +vat.slice(8);
return total === expect;
}
temp = 0;
for (var j = 0; j < 8; j++) {
temp += +vat.charAt(j) * (j + 3);
}
total = temp % 11;
if (total === 10) total = 0;
expect = +vat.slice(8);
return total === expect;
};
var isPhysicalPerson = function () {
// 10 digit VAT code - see if it relates to a standard physical person
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
// Check month
var month = +vat.slice(2, 4);
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
// Extract the next digit and multiply by the counter.
multipliers = [2, 4, 8, 5, 10, 9, 7, 3, 6];
total = 0;
for (var k = 0; k < 9; k++) {
total += +vat.charAt(k) * multipliers[k];
}
// Establish check digit.
total = total % 11;
if (total === 10) total = 0;
// Check to see if the check digit given is correct, If not, try next type of person
if (total === +vat.substr(9, 1)) return true;
}
}
return false;
};
// It doesn't relate to a standard physical person - see if it relates to a foreigner.
var isForeigner = function () {
// Extract the next digit and multiply by the counter.
multipliers = [21, 19, 17, 13, 11, 9, 7, 3, 1];
total = 0;
for (var l = 0; l < 9; l++) {
total += +vat.charAt(l) * multipliers[l];
}
// Check to see if the check digit given is correct, If not, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true;
}
};
var miscellaneousVAT = function () {
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
// Extract the next digit and multiply by the counter.
multipliers = [4, 3, 2, 7, 6, 5, 4, 3, 2];
total = 0;
for (var m = 0; m < 9; m++) {
total += +vat.charAt(m) * multipliers[m];
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(9, 1);
return total === expect;
};
if (vat.length === 9) {
return checkNineLengthVat();
} else {
return isPhysicalPerson() || isForeigner() || miscellaneousVAT();
//TODO (S.Panfilov) this is not cross-browser check
if (Array.isArray(regex)) {
for (var i = 0; i < regex.length; i++) {
if (_validate(vat, regex[i], countryName)) return true;
}
} else {
if (_validate(vat, regex, countryName)) return true;
}
}
}
return false;
},
switzerland: function (vat) {
var expect;
}
};
// Checks the check digits of a Swiss VAT number.
var expect;
var temp;
// Extract the next digit and multiply by the counter.
var multipliers = [5, 4, 3, 2, 7, 6, 5, 4];
var total = 0;
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
var _checks = {
austria: function (vat, countryName) {
var total = 0;
for (var i = 0; i < 7; i++) {
temp = vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
total = 10 - (total + 4) % 10;
if (total === 10) total = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(8, 1);
return total === expect;
},
cyprus: function (vat) {
var expect;
expect = +vat.slice(7, 8);
// Checks the check digits of a Cypriot VAT number.
return total === expect;
},
belgium: function (vat, countryName) {
if (vat.length === 9) vat = "0" + vat;
if (+vat.slice(1, 2) === 0) return false;
// Not allowed to start with '12'
if (+vat.slice(0, 2) === 12) return false;
var check = (97 - +vat.slice(0, 8) % 97);
expect = +vat.slice(8, 10);
return check === expect;
},
bulgaria: function (vat, countryName) {
var checkNineLengthVat = function () {
var total = 0;
temp = 0;
for (var i = 0; i < 8; i++) {
temp += +vat.charAt(i) * (i + 1);
}
// Extract the next digit and multiply by the counter.
var total = 0;
for (var i = 0; i < 8; i++) {
var temp = +vat.charAt(i);
if (i % 2 === 0) {
switch (temp) {
case 0:
temp = 1;
break;
case 1:
temp = 0;
break;
case 2:
temp = 5;
break;
case 3:
temp = 7;
break;
case 4:
temp = 9;
break;
default:
temp = temp * 2 + 3;
}
}
total += temp;
}
total = temp % 11;
if (total !== 10) {
expect = +vat.slice(8);
return total === expect;
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
temp = 0;
for (var j = 0; j < 8; j++) {
temp += +vat.charAt(j) * (j + 3);
}
// Check to see if the check digit given is correct
expect = vat.substr(8, 1);
return total === expect;
},
czech_republic: function (vat) {
var expect;
total = temp % 11;
if (total === 10) total = 0;
expect = +vat.slice(8);
// Checks the check digits of a Czech Republic VAT number.
return total === expect;
};
var total = 0;
var multipliers = [8, 7, 6, 5, 4, 3, 2];
var isPhysicalPerson = function () {
var total = 0;
// 10 digit VAT code - see if it relates to a standard physical person
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
// Check month
var month = +vat.slice(2, 4);
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var czExp = [];
czExp[0] = (/^\d{8}$/);
czExp[1] = (/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/);
czExp[2] = (/^6\d{8}$/);
czExp[3] = (/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/);
// Legal entities
if (czExp[0].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * multipliers[i];
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
total = 0;
for (var k = 0; k < 9; k++) {
total += +vat.charAt(k) * CONDITIONS[countryName].multipliers.physical[k];
}
// Individuals type 1
//else if (czExp[1].test(vat)) {
//TODO (S.Panfilov) It's seems to be an error
// return !(temp = +vat.slice(0, 2) > 53);
//
//}
// Individuals type 2
else if (czExp[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var j = 0; j < 7; j++) {
total += +vat.charAt(j + 1) * multipliers[j];
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Convert calculated check digit according to a lookup table;
var lookup = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10];
expect = +vat.slice(8, 9);
return lookup[total - 1] === expect;
}
// Individuals type 3
else if (czExp[3].test(vat)) {
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8);
expect = +vat % 11 === 0;
return !!(temp % 11 === 0 && expect);
}
// else error
return false;
},
germany: function (vat) {
var expect;
// Checks the check digits of a German VAT number.
var product = 10;
var sum = 0;
var checkDigit = 0;
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement peculiar algorithm!.
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
// Establish check digit.
if (11 - product === 10) {
checkDigit = 0;
} else {
checkDigit = 11 - product;
}
// Compare it with the last two characters of the VAT number. If the same, then it is a valid
// check digit.
expect = +vat.slice(8, 9);
return checkDigit === expect;
},
denmark: function (vat) {
var total = 0;
var multipliers = [2, 7, 6, 5, 4, 3, 2, 1];
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
return total % 11 === 0;
},
estonia: function (vat) {
var expect;
// Checks the check digits of an Estonian VAT number.
var total = 0;
var multipliers = [3, 7, 1, 3, 7, 1, 3, 7];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits using modulus 10.
total = 10 - total % 10;
total = total % 11;
if (total === 10) total = 0;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
greece: function (vat) {
var expect;
// Check to see if the check digit given is correct, If not, try next type of person
if (total === +vat.substr(9, 1)) return true;
}
}
// Checks the check digits of a Greek VAT number.
return false;
var total = 0;
var multipliers = [256, 128, 64, 32, 16, 8, 4, 2];
};
//eight character numbers should be prefixed with an 0.
if (vat.length === 8) {
vat = "0" + vat;
}
// It doesn't relate to a standard physical person - see if it relates to a foreigner.
var isForeigner = function () {
var total = 0;
// Extract the next digit and multiply by the counter.
total = 0;
for (var l = 0; l < 9; l++) {
total += +vat.charAt(l) * CONDITIONS[countryName].multipliers.foreigner[l];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Check to see if the check digit given is correct, If not, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true;
}
};
// Establish check digit.
total = total % 11;
if (total > 9) {
total = 0;
}
var miscellaneousVAT = function () {
var total = 0;
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
spain: function (vat) {
var expect;
total = 0;
for (var m = 0; m < 9; m++) {
total += +vat.charAt(m) * CONDITIONS[countryName].multipliers.miscellaneous[m];
}
// Checks the check digits of a Spanish VAT number.
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
var total = 0;
var temp = 0;
var multipliers = [2, 1, 2, 1, 2, 1, 2];
var esExp = [];
esExp[0] = (/^[A-H|J|U|V]\d{8}$/);
esExp[1] = (/^[A-H|N-S|W]\d{7}[A-J]$/);
esExp[2] = (/^[0-9|Y|Z]\d{7}[A-Z]$/);
esExp[3] = (/^[K|L|M|X]\d{7}[A-Z]$/);
var i = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(9, 1);
return total === expect;
};
// National juridical entities
if (esExp[0].test(vat)) {
if (vat.length === 9) {
return checkNineLengthVat();
} else {
return isPhysicalPerson() || isForeigner() || miscellaneousVAT();
}
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Now calculate the check digit itself.
total = 10 - total % 10;
if (total === 10) {
total = 0;
}
},
switzerland: function (vat, countryName) {
var total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
// Juridical entities other than national ones
else if (esExp[1].test(vat)) {
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(8, 1);
return total === expect;
},
cyprus: function (vat, countryName) {
var total = 0;
// Not allowed to start with '12'
if (+vat.slice(0, 2) === 12) return false;
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Extract the next digit and multiply by the counter.
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total + 64);
for (var i = 0; i < 8; i++) {
var temp = +vat.charAt(i);
if (i % 2 === 0) {
switch (temp) {
case 0:
temp = 1;
break;
case 1:
temp = 0;
break;
case 2:
temp = 5;
break;
case 3:
temp = 7;
break;
case 4:
temp = 9;
break;
default:
temp = temp * 2 + 3;
}
}
total += temp;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(8, 9);
return total === expect;
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
// Personal number (NIF) (starting with numeric of Y or Z)
else if (esExp[2].test(vat)) {
var tempnumber = vat;
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, "1");
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, "2");
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23);
return tempnumber.charAt(8) === expect;
}
// Check to see if the check digit given is correct
expect = vat.substr(8, 1);
return total === expect;
},
czech_republic: function (vat, countryName) {
var total = 0;
// Personal number (NIF) (starting with K, L, M, or X)
else if (esExp[3].test(vat)) {
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23);
return vat.charAt(8) === expect;
}
// Legal entities
if (CONDITIONS[countryName].additional[0].test(vat)) {
else return false;
},
europe: function () {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// We know little about EU numbers apart from the fact that the first 3 digits represent the
// country, and that there are nine digits in total.
return true;
},
finland: function (vat) {
var expect;
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Checks the check digits of a Finnish VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
}
var total = 0;
var multipliers = [7, 9, 10, 5, 8, 4, 2];
// Individuals type 2
else if (CONDITIONS[countryName].additional[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Extract the next digit and multiply by the counter.
for (var j = 0; j < 7; j++) {
total += +vat.charAt(j + 1) * CONDITIONS[countryName].multipliers[j];
}
// Establish check digit.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
france: function (vat) {
var expect;
// Convert calculated check digit according to a lookup table;
expect = +vat.slice(8, 9);
return CONDITIONS[countryName].lookup[total - 1] === expect;
}
// Checks the check digits of a French VAT number.
// Individuals type 3
else if (CONDITIONS[countryName].additional[3].test(vat)) {
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8);
expect = +vat % 11 === 0;
return !!(temp % 11 === 0 && expect);
}
if (!(/^\d{11}$/).test(vat)) {
return true;
}
// else error
return false;
},
germany: function (vat, countryName) {
// Extract the last nine digits as an integer.
var total = +vat.substring(2);
// Establish check digit.
total = (total * 100 + 12) % 97;
// Checks the check digits of a German VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(0, 2);
return total === expect;
},
united_kingdom: function (vat) {
var expect;
var product = 10;
var sum = 0;
var checkDigit = 0;
for (var i = 0; i < 8; i++) {
// Checks the check digits of a UK VAT number.
// Extract the next digit and implement peculiar algorithm!.
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
var multipliers = [8, 7, 6, 5, 4, 3, 2];
// Establish check digit.
if (11 - product === 10) {
checkDigit = 0;
} else {
checkDigit = 11 - product;
}
// Government departments
if (vat.substr(0, 2) === 'GD') {
expect = 500;
return vat.substr(2, 3) < expect;
}
// Compare it with the last two characters of the VAT number. If the same, then it is a valid
// check digit.
expect = +vat.slice(8, 9);
return checkDigit === expect;
},
denmark: function (vat, countryName) {
var total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Health authorities
if (vat.substr(0, 2) === 'HA') {
expect = 499;
return vat.substr(2, 3) > expect;
}
return total % 11 === 0;
},
estonia: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Standard and commercial numbers
var total = 0;
// Establish check digits using modulus 10.
total = 10 - total % 10;
if (total === 10) total = 0;
// 0 VAT numbers disallowed!
if (+vat.slice(0) === 0) return false;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
greece: function (vat, countryName) {
var total = 0;
//eight character numbers should be prefixed with an 0.
if (vat.length === 8) {
vat = "0" + vat;
}
// Check range is OK for modulus 97 calculation
var no = +vat.slice(0, 7);
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digit.
total = total % 11;
if (total > 9) {
total = 0;
}
// Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our
// VAT number could use either system, so we check it against both.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
spain: function (vat, countryName) {
var i = 0;
var total = 0;
// Establish check digits by subtracting 97 from total until negative.
var checkDigit = total;
while (checkDigit > 0) {
checkDigit = checkDigit - 97;
}
// National juridical entities
if (CONDITIONS[countryName].additional[0].test(vat)) {
// Get the absolute value and compare it with the last two characters of the VAT number. If the
// same, then it is a valid traditional check digit. However, even then the number must fit within
// certain specified ranges.
checkDigit = Math.abs(checkDigit);
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Now calculate the check digit itself.
total = 10 - total % 10;
if (total === 10) {
total = 0;
}
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (checkDigit >= 55)
checkDigit = checkDigit - 55;
else
checkDigit = checkDigit + 42;
expect = +vat.slice(7, 9);
return !!(checkDigit === expect && no > 1000000);
},
croatia: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
// Juridical entities other than national ones
else if (CONDITIONS[countryName].additional[1].test(vat)) {
var product = 10;
var sum = 0;
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
for (var i = 0; i < 10; i++) {
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total + 64);
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(8, 9);
return total === expect;
}
product = (2 * sum) % 11;
}
// Personal number (NIF) (starting with numeric of Y or Z)
else if (CONDITIONS[countryName].additional[2].test(vat)) {
var tempnumber = vat;
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, "1");
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, "2");
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23);
return tempnumber.charAt(8) === expect;
}
// Now check that we have the right check digit
expect = +vat.slice(10, 11);
return (product + expect) % 10 === 1;
},
hungary: function (vat) {
var expect;
// Personal number (NIF) (starting with K, L, M, or X)
else if (CONDITIONS[countryName].additional[3].test(vat)) {
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23);
return vat.charAt(8) === expect;
}
// Checks the check digits of a Hungarian VAT number.
else return false;
},
europe: function () {
//TODO (S.Panfilov) wtf?
// We know little about EU numbers apart from the fact that the first 3 digits represent the
// country, and that there are nine digits in total.
return true;
},
finland: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
var total = 0;
var multipliers = [9, 7, 3, 1, 9, 7, 3];
// Establish check digit.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
france: function (vat, countryName) {
var total = 0;
// Checks the check digits of a French VAT number.
if (!(/^\d{11}$/).test(vat)) {
return true;
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10) total = 0;
// Extract the last nine digits as an integer.
total = +vat.substring(2);
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
ireland: function (vat) {
var expect;
// Establish check digit.
total = (total * 100 + 12) % 97;
// Checks the check digits of an Irish VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(0, 2);
return total === expect;
},
united_kingdom: function (vat, countryName) {
var total = 0;
// Government departments
if (vat.substr(0, 2) === 'GD') {
expect = 500;
return vat.substr(2, 3) < expect;
}
var total = 0;
var multipliers = [8, 7, 6, 5, 4, 3, 2];
// Health authorities
if (vat.substr(0, 2) === 'HA') {
expect = 499;
return vat.substr(2, 3) > expect;
}
// If the code is type 1 format, we need to convert it to the new before performing the validation.
if (/^\d[A-Z\*\+]/.test(vat)) {
vat = "0" + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8);
}
// Standard and commercial numbers
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * multipliers[i];
}
// If the number is type 3 then we need to include the trailing A or H in the calculation
if (/^\d{7}[A-Z][AH]$/.test(vat)) {
// Add in a multiplier for the character A (1*9=9) or H (8*9=72)
if (vat.charAt(8) === 'H') {
total += 72;
} else {
total += 9;
}
}
// 0 VAT numbers disallowed!
if (+vat.slice(0) === 0) return false;
// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
if (total === 0) {
total = "W";
} else {
total = String.fromCharCode(total + 64);
}
// Check range is OK for modulus 97 calculation
var no = +vat.slice(0, 7);
// Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(7, 8);
return total === expect;
},
italy: function (vat) {
var expect;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Checks the check digits of an Italian VAT number.
// Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our
// VAT number could use either system, so we check it against both.
var total = 0;
var multipliers = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
var temp;
// Establish check digits by subtracting 97 from total until negative.
var checkDigit = total;
while (checkDigit > 0) {
checkDigit = checkDigit - 97;
}
// The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
if (+vat.slice(0, 7) === 0) {
return false;
}
// Get the absolute value and compare it with the last two characters of the VAT number. If the
// same, then it is a valid traditional check digit. However, even then the number must fit within
// certain specified ranges.
checkDigit = Math.abs(checkDigit);
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
temp = +vat.slice(7, 10);
if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
return false;
}
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (checkDigit >= 55)
checkDigit = checkDigit - 55;
else
checkDigit = checkDigit + 42;
expect = +vat.slice(7, 9);
return !!(checkDigit === expect && no > 1000000);
},
croatia: function (vat, countryName) {
// Extract the next digit and multiply by the appropriate
for (var i = 0; i < 10; i++) {
temp = +vat.charAt(i) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Establish check digit.
total = 10 - total % 10;
if (total > 9) {
total = 0;
}
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
},
lithunia: function (vat) {
var total;
var multipliers;
var expect;
var product = 10;
var sum = 0;
// Checks the check digits of a Lithuanian VAT number.
for (var i = 0; i < 10; i++) {
// 9 character VAT numbers are for legal persons
if (vat.length === 9) {
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false;
product = (2 * sum) % 11;
}
// Extract the next digit and multiply by the counter+1.
total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1);
}
// Now check that we have the right check digit
expect = +vat.slice(10, 11);
return (product + expect) % 10 === 1;
},
hungary: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Can have a double check digit calculation!
if (total % 11 === 10) {
multipliers = [3, 4, 5, 6, 7, 8, 9, 1];
total = 0;
for (var j = 0; j < 8; j++) {
total += +vat.charAt(j) * multipliers[j];
}
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10) total = 0;
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
ireland: function (vat, countryName) {
var total = 0;
// If the code is type 1 format, we need to convert it to the new before performing the validation.
if (/^\d[A-Z\*\+]/.test(vat)) {
vat = "0" + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8);
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// 12 character VAT numbers are for temporarily registered taxpayers
else {
// If the number is type 3 then we need to include the trailing A or H in the calculation
if (/^\d{7}[A-Z][AH]$/.test(vat)) {
// Add in a multiplier for the character A (1*9=9) or H (8*9=72)
if (vat.charAt(8) === 'H') {
total += 72;
} else {
total += 9;
}
}
// 11th character must be one
if (!(/^\d{10}1/).test(vat)) return false;
// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
if (total === 0) {
total = "W";
} else {
total = String.fromCharCode(total + 64);
}
// Extract the next digit and multiply by the counter+1.
total = 0;
multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2];
for (var k = 0; k < 11; k++) {
total += +vat.charAt(k) * multipliers[k];
}
// Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(7, 8);
return total === expect;
},
italy: function (vat, countryName) {
var total = 0;
// The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
if (+vat.slice(0, 7) === 0) {
return false;
}
// Can have a double check digit calculation!
if (total % 11 === 10) {
multipliers = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4];
total = 0;
for (var l = 0; l < 11; l++) {
total += +vat.charAt(l) * multipliers[l];
}
}
temp = +vat.slice(7, 10);
if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
return false;
}
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Extract the next digit and multiply by the appropriate
for (var i = 0; i < 10; i++) {
temp = +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(11, 12);
return total === expect;
}
},
luxembourg: function (vat) {
var expect = +vat.slice(6, 8);
var checkDigit = +vat.slice(0, 6) % 89;
// Checks the check digits of a Luxembourg VAT number.
// Establish check digit.
total = 10 - total % 10;
if (total > 9) {
total = 0;
}
return checkDigit === expect;
},
latvia: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
},
lithunia: function (vat, countryName) {
var total = 0;
// 9 character VAT numbers are for legal persons
if (vat.length === 9) {
// Checks the check digits of a Latvian VAT number.
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false;
// Differentiate between legal entities and natural bodies. For the latter we simply check that
// the first six digits correspond to valid DDMMYY dates.
if ((/^[0-3]/).test(vat)) {
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat);
} else {
// Extract the next digit and multiply by the counter+1.
total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1);
}
var total = 0;
var multipliers = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6];
// Can have a double check digit calculation!
if (total % 11 === 10) {
total = 0;
for (var j = 0; j < 8; j++) {
total += +vat.charAt(j) * CONDITIONS[countryName].multipliers.short[j];
}
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Establish check digits by getting modulus 11.
if (total % 11 === 4 && vat[0] === 9) total = total - 45;
if (total % 11 === 4)
total = 4 - total % 11;
else if (total % 11 > 4)
total = 14 - total % 11;
else if (total % 11 < 4)
total = 3 - total % 11;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
}
},
malta: function (vat) {
var expect;
// 12 character VAT numbers are for temporarily registered taxpayers
else {
// Checks the check digits of a Maltese VAT number.
// 11th character must be one
if (!(/^\d{10}1/).test(vat)) return false;
var total = 0;
var multipliers = [3, 4, 6, 7, 8, 9];
// Extract the next digit and multiply by the counter+1.
total = 0;
for (var k = 0; k < 11; k++) {
total += +vat.charAt(k) * CONDITIONS[countryName].multipliers.med[k];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) total += +vat.charAt(i) * multipliers[i];
// Can have a double check digit calculation!
if (total % 11 === 10) {
total = 0;
for (var l = 0; l < 11; l++) {
total += +vat.charAt(l) * CONDITIONS[countryName].multipliers.alt[l];
}
}
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(6, 8);
return total === expect;
},
netherlands: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(11, 12);
return total === expect;
}
},
luxembourg: function (vat, countryName) {
var expect = +vat.slice(6, 8);
var checkDigit = +vat.slice(0, 6) % 89;
// Checks the check digits of a Luxembourg VAT number.
// Checks the check digits of a Dutch VAT number.
return checkDigit === expect;
},
latvia: function (vat, countryName) {
var total = 0;
var total = 0;
var multipliers = [9, 8, 7, 6, 5, 4, 3, 2];
// Differentiate between legal entities and natural bodies. For the latter we simply check that
// the first six digits correspond to valid DDMMYY dates.
if ((/^[0-3]/).test(vat)) {
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat);
} else {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Establish check digits by getting modulus 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Establish check digits by getting modulus 11.
if (total % 11 === 4 && vat[0] === 9) total = total - 45;
if (total % 11 === 4)
total = 4 - total % 11;
else if (total % 11 > 4)
total = 14 - total % 11;
else if (total % 11 < 4)
total = 3 - total % 11;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
norway: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
}
},
malta: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Checks the check digits of a Norwegian VAT number.
// See http://www.brreg.no/english/coordination/number.html
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
var total = 0;
var multipliers = [3, 2, 7, 6, 5, 4, 3, 2];
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(6, 8);
return total === expect;
},
netherlands: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits by getting modulus 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Establish check digits by getting modulus 11. Check digits > 9 are invalid
total = 11 - total % 11;
if (total === 11) {
total = 0;
}
if (total < 10) {
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
norway: function (vat, countryName) {
var total = 0;
// See http://www.brreg.no/english/coordination/number.html
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
},
poland: function (vat) {
var expect;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Checks the check digits of a Polish VAT number.
// Establish check digits by getting modulus 11. Check digits > 9 are invalid
total = 11 - total % 11;
if (total === 11) {
total = 0;
}
if (total < 10) {
var total = 0;
var multipliers = [6, 5, 7, 2, 3, 4, 5, 6, 7];
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
},
poland: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return total === expect;
},
portugal: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return total === expect;
},
portugal: function (vat) {
var expect;
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Checks the check digits of a Portugese VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
romania: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
var vatLength = vat.length;
var multipliers = CONDITIONS[countryName].multipliers.slice(10 - vatLength);
var total = 0;
var multipliers = [9, 8, 7, 6, 5, 4, 3, 2];
for (var i = 0; i < vat.length - 1; i++) {
total += +vat.charAt(i) * multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total === 10) total = 0;
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(vat.length - 1, vat.length);
return total === expect;
},
serbia: function (vat, countryName) {
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
romania: function (vat) {
var expect;
// Checks the check digits of a Romanian VAT number.
// Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.
var multipliers = [7, 5, 3, 2, 1, 7, 5, 3, 2];
var product = 10;
var sum = 0;
var checkDigit;
// Extract the next digit and multiply by the counter.
var vatLength = vat.length;
multipliers = multipliers.slice(10 - vatLength);
var total = 0;
for (var i = 0; i < vat.length - 1; i++) {
total += +vat.charAt(i) * multipliers[i];
}
for (var i = 0; i < 8; i++) {
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total === 10) total = 0;
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(vat.length - 1, vat.length);
return total === expect;
},
serbia: function (vat) {
var expect;
// Now check that we have the right check digit
expect = 1;
checkDigit = (product + (+vat.slice(8, 9))) % 10;
return checkDigit === expect;
},
russia: function (vat, countryName) {
var total = 0;
var expect2;
// Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.
// Checks the check digits of a Russian INN number
// See http://russianpartner.biz/test_inn.html for algorithm
var product = 10;
var sum = 0;
var checkDigit;
// 10 digit INN numbers
if (vat.length === 10) {
for (var i = 0; i < 8; i++) {
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers.m_1[i];
}
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
total = total % 11;
if (total > 9) {
total = total % 10;
}
// Now check that we have the right check digit
expect = 1;
checkDigit = (product + (+vat.slice(8, 9))) % 10;
return checkDigit === expect;
},
russia: function (vat) {
var expect;
var expect2;
// Compare it with the last character of the VAT number. If it is the same, then it's valid
expect = +vat.slice(9, 10);
return total === expect;
// Checks the check digits of a Russian INN number
// See http://russianpartner.biz/test_inn.html for algorithm
// 12 digit INN numbers
} else if (vat.length === 12) {
var total1 = 0;
var total2 = 0;
// 10 digit INN numbers
if (vat.length === 10) {
var total = 0;
var multipliers = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * multipliers[i];
}
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * CONDITIONS[countryName].multipliers.m_2[j];
}
total = total % 11;
if (total > 9) {
total = total % 10;
}
total1 = total1 % 11;
if (total1 > 9) {
total1 = total1 % 10;
}
// Compare it with the last character of the VAT number. If it is the same, then it's valid
expect = +vat.slice(9, 10);
return total === expect;
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * CONDITIONS[countryName].multipliers.m_3[k];
}
// 12 digit INN numbers
} else if (vat.length === 12) {
var total1 = 0;
var multipliers1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
var total2 = 0;
var multipliers2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
total2 = total2 % 11;
if (total2 > 9) {
total2 = total2 % 10;
}
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * multipliers1[j];
}
// Compare the first check with the 11th character and the second check with the 12th and last
// character of the VAT number. If they're both the same, then it's valid
//expect = +vat.slice(10, 11);
expect = (total1 === +vat.slice(10, 11));
//expect2 = +vat.slice(11, 12);
expect2 = (total2 === +vat.slice(11, 12));
return (expect) && (expect2);
}
},
sweden: function (vat, countryName) {
// Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
var R = 0;
var digit;
for (var i = 0; i < 9; i = i + 2) {
digit = +vat.charAt(i);
R += Math.floor(digit / 5) + ((digit * 2) % 10);
}
total1 = total1 % 11;
if (total1 > 9) {
total1 = total1 % 10;
}
// Calculate S where S = C2 + C4 + C6 + C8
var S = 0;
for (var j = 1; j < 9; j = j + 2) {
S += +vat.charAt(j);
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * multipliers2[k];
}
var checkDigit = (10 - (R + S) % 10) % 10;
total2 = total2 % 11;
if (total2 > 9) {
total2 = total2 % 10;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
// Compare the first check with the 11th character and the second check with the 12th and last
// character of the VAT number. If they're both the same, then it's valid
expect = +vat.slice(10, 11);
expect2 = +vat.slice(11, 12);
return (expect) && (expect2);
}
},
sweden: function (vat) {
var expect;
return checkDigit === expect;
},
slovenia: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
var R = 0;
var digit;
for (var i = 0; i < 9; i = i + 2) {
digit = +vat.charAt(i);
R += Math.floor(digit / 5) + ((digit * 2) % 10);
}
// Establish check digits using modulus 11
total = 11 - total % 11;
if (total === 10) {
total = 0;
}
// Calculate S where S = C2 + C4 + C6 + C8
var S = 0;
for (var j = 1; j < 9; j = j + 2) {
S += +vat.charAt(j);
}
// Compare the number with the last character of the VAT number. If it is the
// same, then it's a valid check digit.
expect = +vat.slice(7, 8);
return !!(total !== 11 && total === expect);
},
slovakia_republic: function (vat, countryName) {
var expect = 0;
var checkDigit = (vat % 11);
// Checks the check digits of a Slovakian VAT number.
// Check that the modulus of the whole VAT number is 0 - else error
return checkDigit === expect;
}
};
var checkDigit = (10 - (R + S) % 10) % 10;
if (typeof module === 'object' && module.exports) module.exports = exports;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return checkDigit === expect;
},
slovenia: function (vat) {
var expect;
// Checks the check digits of a Slovenian VAT number.
var total = 0;
var multipliers = [8, 7, 6, 5, 4, 3, 2];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits using modulus 11
total = 11 - total % 11;
if (total === 10) {
total = 0;
}
// Compare the number with the last character of the VAT number. If it is the
// same, then it's a valid check digit.
expect = +vat.slice(7, 8);
return !!(total !== 11 && total === expect);
},
slovakia_republic: function (vat) {
var expect = 0;
var checkDigit = (vat % 11);
// Checks the check digits of a Slovakian VAT number.
// Check that the modulus of the whole VAT number is 0 - else error
return checkDigit === expect;
}
};
if (typeof module === 'object' && module.exports) module.exports = exports;
return exports;
return exports;
})();

@@ -1,2 +0,2 @@

var jsvat=function(){"use strict";function r(r,t){return t.test(r)}function t(r,t,e){var n=t.exec(r),a=n[2];return i[e](a)}function e(e,n,a){var i=!1;return r(e,n)&&(i=t(e,n,a)),i}var n={austria:/^(AT)U(\d{8})$/,belgium:/^(BE)(0?\d{9})$/,bulgaria:/^(BG)(\d{9,10})$/,switzerland:/^(CHE)(\d{9})(MWST)?$/,cyprus:/^(CY)([0-59]\d{7}[A-Z])$/,czech_republic:/^(CZ)(\d{8,10})(\d{3})?$/,germany:/^(DE)([1-9]\d{8})$/,denmark:/^(DK)(\d{8})$/,estonia:/^(EE)(10\d{7})$/,greece:/^(EL)(\d{9})$/,spain:[/^(ES)([A-Z]\d{8})$/,/^(ES)([A-HN-SW]\d{7}[A-J])$/,/^(ES)([0-9YZ]\d{7}[A-Z])$/,/^(ES)([KLMX]\d{7}[A-Z])$/],europe:/^(EU)(\d{9})$/,finland:/^(FI)(\d{8})$/,france:[/^(FR)(\d{11})$/,/^(FR)([A-HJ-NP-Z]\d{10})$/,/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,/^(FR)([A-HJ-NP-Z]{2}\d{9})$/],united_kingdom:[/^(GB)?(\d{9})$/,/^(GB)?(\d{12})$/,/^(GB)?(GD\d{3})$/,/^(GB)?(HA\d{3})$/],croatia:/^(HR)(\d{11})$/,hungary:/^(HU)(\d{8})$/,ireland:[/^(IE)(\d{7}[A-W])$/,/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,/^(IE)(\d{7}[A-W][AH])$/],italy:/^(IT)(\d{11})$/,latvia:/^(LV)(\d{11})$/,lithunia:/^(LT)(\d{9}|\d{12})$/,luxembourg:/^(LU)(\d{8})$/,malta:/^(MT)([1-9]\d{7})$/,netherlands:/^(NL)(\d{9})B\d{2}$/,norway:/^(NO)(\d{9})$/,poland:/^(PL)(\d{10})$/,portugal:/^(PT)(\d{9})$/,romania:/^(RO)([1-9]\d{1,9})$/,russia:/^(RU)(\d{10}|\d{12})$/,serbia:/^(RS)(\d{9})$/,slovenia:/^(SI)([1-9]\d{7})$/,slovakia_republic:/^(SK)([1-9]\d[2346-9]\d{7})$/,sweden:/^(SE)(\d{10}01)$/},a={checkVAT:function(r){if(!r)return!1;r=r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"");for(var t in n)if(n.hasOwnProperty(t)){var a=n[t];if(Array.isArray(a)){for(var i=0;i<a.length;i++)if(e(r,a[i],t))return!0}else if(e(r,a,t))return!0}return!1}},i={austria:function(r){for(var t,e,n=0,a=[1,2,1,2,1,2,1],i=0;7>i;i++)t=r.charAt(i)*a[i],n+=t>9?Math.floor(t/10)+t%10:t;return n=10-(n+4)%10,10===n&&(n=0),e=+r.slice(7,8),n===e},belgium:function(r){var t,e;return 9===r.length&&(r="0"+r),0===+r.slice(1,2)?!1:(e=97-+r.slice(0,8)%97,t=+r.slice(8,10),e===t)},bulgaria:function(r){var t,e,n,a,i=function(){n=0;for(var e=0;8>e;e++)n+=+r.charAt(e)*(e+1);if(a=n%11,10!==a)return t=+r.slice(8),a===t;n=0;for(var i=0;8>i;i++)n+=+r.charAt(i)*(i+3);return a=n%11,10===a&&(a=0),t=+r.slice(8),a===t},c=function(){if(/^\d\d[0-5]\d[0-3]\d\d{4}$/.test(r)){var t=+r.slice(2,4);if(t>0&&13>t||t>20&&33>t||t>40&&53>t){e=[2,4,8,5,10,9,7,3,6],a=0;for(var n=0;9>n;n++)a+=+r.charAt(n)*e[n];if(a%=11,10===a&&(a=0),a===+r.substr(9,1))return!0}}return!1},u=function(){e=[21,19,17,13,11,9,7,3,1],a=0;for(var t=0;9>t;t++)a+=+r.charAt(t)*e[t];return a%10===+r.substr(9,1)?!0:void 0},s=function(){e=[4,3,2,7,6,5,4,3,2],a=0;for(var n=0;9>n;n++)a+=+r.charAt(n)*e[n];return a=11-a%11,10===a?!1:(11===a&&(a=0),t=+r.substr(9,1),a===t)};return 9===r.length?i():c()||u()||s()},switzerland:function(r){for(var t,e=[5,4,3,2,7,6,5,4],n=0,a=0;8>a;a++)n+=+r.charAt(a)*e[a];return n=11-n%11,10===n?!1:(11===n&&(n=0),t=+r.substr(8,1),n===t)},cyprus:function(r){var t;if(12===+r.slice(0,2))return!1;for(var e=0,n=0;8>n;n++){var a=+r.charAt(n);if(n%2===0)switch(a){case 0:a=1;break;case 1:a=0;break;case 2:a=5;break;case 3:a=7;break;case 4:a=9;break;default:a=2*a+3}e+=a}return e%=26,e=String.fromCharCode(e+65),t=r.substr(8,1),e===t},czech_republic:function(r){var t,e=0,n=[8,7,6,5,4,3,2],a=[];if(a[0]=/^\d{8}$/,a[1]=/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/,a[2]=/^6\d{8}$/,a[3]=/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/,a[0].test(r)){for(var i=0;7>i;i++)e+=+r.charAt(i)*n[i];return e=11-e%11,10===e&&(e=0),11===e&&(e=1),t=+r.slice(7,8),e===t}if(a[2].test(r)){for(var c=0;7>c;c++)e+=+r.charAt(c+1)*n[c];e=11-e%11,10===e&&(e=0),11===e&&(e=1);var u=[8,7,6,5,4,3,2,1,0,9,10];return t=+r.slice(8,9),u[e-1]===t}if(a[3].test(r)){var s=+r.slice(0,2)+r.slice(2,4)+r.slice(4,6)+r.slice(6,8)+r.slice(8);return t=+r%11===0,!(s%11!==0||!t)}return!1},germany:function(r){for(var t,e=10,n=0,a=0,i=0;8>i;i++)n=(+r.charAt(i)+e)%10,0===n&&(n=10),e=2*n%11;return a=11-e===10?0:11-e,t=+r.slice(8,9),a===t},denmark:function(r){for(var t=0,e=[2,7,6,5,4,3,2,1],n=0;8>n;n++)t+=+r.charAt(n)*e[n];return t%11===0},estonia:function(r){for(var t,e=0,n=[3,7,1,3,7,1,3,7],a=0;8>a;a++)e+=+r.charAt(a)*n[a];return e=10-e%10,10===e&&(e=0),t=+r.slice(8,9),e===t},greece:function(r){var t,e=0,n=[256,128,64,32,16,8,4,2];8===r.length&&(r="0"+r);for(var a=0;8>a;a++)e+=+r.charAt(a)*n[a];return e%=11,e>9&&(e=0),t=+r.slice(8,9),e===t},spain:function(r){var t,e=0,n=0,a=[2,1,2,1,2,1,2],i=[];i[0]=/^[A-H|J|U|V]\d{8}$/,i[1]=/^[A-H|N-S|W]\d{7}[A-J]$/,i[2]=/^[0-9|Y|Z]\d{7}[A-Z]$/,i[3]=/^[K|L|M|X]\d{7}[A-Z]$/;var c=0;if(i[0].test(r)){for(c=0;7>c;c++)n=r.charAt(c+1)*a[c],e+=n>9?Math.floor(n/10)+n%10:n;return e=10-e%10,10===e&&(e=0),t=+r.slice(8,9),e===t}if(i[1].test(r)){for(c=0;7>c;c++)n=r.charAt(c+1)*a[c],e+=n>9?Math.floor(n/10)+n%10:n;return e=10-e%10,e=String.fromCharCode(e+64),t=r.slice(8,9),e===t}if(i[2].test(r)){var u=r;return"Y"===u.substring(0,1)&&(u=u.replace(/Y/,"1")),"Z"===u.substring(0,1)&&(u=u.replace(/Z/,"2")),t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+u.substring(0,8)%23),u.charAt(8)===t}return i[3].test(r)?(t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+r.substring(1,8)%23),r.charAt(8)===t):!1},europe:function(){return!0},finland:function(r){for(var t,e=0,n=[7,9,10,5,8,4,2],a=0;7>a;a++)e+=+r.charAt(a)*n[a];return e=11-e%11,e>9&&(e=0),t=+r.slice(7,8),e===t},france:function(r){var t;if(!/^\d{11}$/.test(r))return!0;var e=+r.substring(2);return e=(100*e+12)%97,t=+r.slice(0,2),e===t},united_kingdom:function(r){var t,e=[8,7,6,5,4,3,2];if("GD"===r.substr(0,2))return t=500,r.substr(2,3)<t;if("HA"===r.substr(0,2))return t=499,r.substr(2,3)>t;var n=0;if(0===+r.slice(0))return!1;for(var a=+r.slice(0,7),i=0;7>i;i++)n+=+r.charAt(i)*e[i];for(var c=n;c>0;)c-=97;return c=Math.abs(c),c===+r.slice(7,9)&&9990001>a&&(1e5>a||a>999999)&&(9490001>a||a>97e5)?!0:(c>=55?c-=55:c+=42,t=+r.slice(7,9),!!(c===t&&a>1e6))},croatia:function(r){for(var t,e=10,n=0,a=0;10>a;a++)n=(+r.charAt(a)+e)%10,0===n&&(n=10),e=2*n%11;return t=+r.slice(10,11),(e+t)%10===1},hungary:function(r){for(var t,e=0,n=[9,7,3,1,9,7,3],a=0;7>a;a++)e+=+r.charAt(a)*n[a];return e=10-e%10,10===e&&(e=0),t=+r.slice(7,8),e===t},ireland:function(r){var t,e=0,n=[8,7,6,5,4,3,2];/^\d[A-Z\*\+]/.test(r)&&(r="0"+r.substring(2,7)+r.substring(0,1)+r.substring(7,8));for(var a=0;7>a;a++)e+=+r.charAt(a)*n[a];return/^\d{7}[A-Z][AH]$/.test(r)&&(e+="H"===r.charAt(8)?72:9),e%=23,e=0===e?"W":String.fromCharCode(e+64),t=r.slice(7,8),e===t},italy:function(r){var t,e,n=0,a=[1,2,1,2,1,2,1,2,1,2];if(0===+r.slice(0,7))return!1;if(e=+r.slice(7,10),1>e||e>201&&999!==e&&888!==e)return!1;for(var i=0;10>i;i++)e=+r.charAt(i)*a[i],n+=e>9?Math.floor(e/10)+e%10:e;return n=10-n%10,n>9&&(n=0),t=+r.slice(10,11),n===t},lithunia:function(r){var t,e,n;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;t=0;for(var a=0;8>a;a++)t+=+r.charAt(a)*(a+1);if(t%11===10){e=[3,4,5,6,7,8,9,1],t=0;for(var i=0;8>i;i++)t+=+r.charAt(i)*e[i]}return t%=11,10===t&&(t=0),n=+r.slice(8,9),t===n}if(!/^\d{10}1/.test(r))return!1;t=0,e=[1,2,3,4,5,6,7,8,9,1,2];for(var c=0;11>c;c++)t+=+r.charAt(c)*e[c];if(t%11===10){e=[3,4,5,6,7,8,9,1,2,3,4],t=0;for(var u=0;11>u;u++)t+=+r.charAt(u)*e[u]}return t%=11,10===t&&(t=0),n=+r.slice(11,12),t===n},luxembourg:function(r){var t=+r.slice(6,8),e=+r.slice(0,6)%89;return e===t},latvia:function(r){var t;if(/^[0-3]/.test(r))return!!/^[0-3][0-9][0-1][0-9]/.test(r);for(var e=0,n=[9,1,4,8,3,10,2,5,7,6],a=0;10>a;a++)e+=+r.charAt(a)*n[a];return e%11===4&&9===r[0]&&(e-=45),e%11===4?e=4-e%11:e%11>4?e=14-e%11:4>e%11&&(e=3-e%11),t=+r.slice(10,11),e===t},malta:function(r){for(var t,e=0,n=[3,4,6,7,8,9],a=0;6>a;a++)e+=+r.charAt(a)*n[a];return e=37-e%37,t=+r.slice(6,8),e===t},netherlands:function(r){for(var t,e=0,n=[9,8,7,6,5,4,3,2],a=0;8>a;a++)e+=+r.charAt(a)*n[a];return e%=11,e>9&&(e=0),t=+r.slice(8,9),e===t},norway:function(r){for(var t,e=0,n=[3,2,7,6,5,4,3,2],a=0;8>a;a++)e+=+r.charAt(a)*n[a];return e=11-e%11,11===e&&(e=0),10>e?(t=+r.slice(8,9),e===t):void 0},poland:function(r){for(var t,e=0,n=[6,5,7,2,3,4,5,6,7],a=0;9>a;a++)e+=+r.charAt(a)*n[a];return e%=11,e>9&&(e=0),t=+r.slice(9,10),e===t},portugal:function(r){for(var t,e=0,n=[9,8,7,6,5,4,3,2],a=0;8>a;a++)e+=+r.charAt(a)*n[a];return e=11-e%11,e>9&&(e=0),t=+r.slice(8,9),e===t},romania:function(r){var t,e=[7,5,3,2,1,7,5,3,2],n=r.length;e=e.slice(10-n);for(var a=0,i=0;i<r.length-1;i++)a+=+r.charAt(i)*e[i];return a=10*a%11,10===a&&(a=0),t=+r.slice(r.length-1,r.length),a===t},serbia:function(r){for(var t,e,n=10,a=0,i=0;8>i;i++)a=(+r.charAt(i)+n)%10,0===a&&(a=10),n=2*a%11;return t=1,e=(n+ +r.slice(8,9))%10,e===t},russia:function(r){var t,e;if(10===r.length){for(var n=0,a=[2,4,10,3,5,9,4,6,8,0],i=0;10>i;i++)n+=+r.charAt(i)*a[i];return n%=11,n>9&&(n%=10),t=+r.slice(9,10),n===t}if(12===r.length){for(var c=0,u=[7,2,4,10,3,5,9,4,6,8,0],s=0,o=[3,7,2,4,10,3,5,9,4,6,8,0],f=0;11>f;f++)c+=+r.charAt(f)*u[f];c%=11,c>9&&(c%=10);for(var l=0;11>l;l++)s+=+r.charAt(l)*o[l];return s%=11,s>9&&(s%=10),t=+r.slice(10,11),e=+r.slice(11,12),t&&e}},sweden:function(r){for(var t,e,n=0,a=0;9>a;a+=2)e=+r.charAt(a),n+=Math.floor(e/5)+2*e%10;for(var i=0,c=1;9>c;c+=2)i+=+r.charAt(c);var u=(10-(n+i)%10)%10;return t=+r.slice(9,10),u===t},slovenia:function(r){for(var t,e=0,n=[8,7,6,5,4,3,2],a=0;7>a;a++)e+=+r.charAt(a)*n[a];return e=11-e%11,10===e&&(e=0),t=+r.slice(7,8),!(11===e||e!==t)},slovakia_republic:function(r){var t=0,e=r%11;return e===t}};return"object"==typeof module&&module.exports&&(module.exports=a),a}();
var jsvat=function(){"use strict";function r(r,e){return e.test(r)}function e(r,e,t){var i=e.exec(r),l=i[2];return u[t](l,t)}function t(t,i,l){var a=!1;return r(t,i)&&(a=e(t,i,l)),a}var i,l,a={austria:{multipliers:[1,2,1,2,1,2,1],regex:/^(AT)U(\d{8})$/},belgium:{regex:/^(BE)(0?\d{9})$/},bulgaria:{multipliers:{physical:[2,4,8,5,10,9,7,3,6],foreigner:[21,19,17,13,11,9,7,3,1],miscellaneous:[4,3,2,7,6,5,4,3,2]},regex:/^(BG)(\d{9,10})$/},switzerland:{multipliers:[5,4,3,2,7,6,5,4],regex:/^(CHE)(\d{9})(MWST)?$/},cyprus:{regex:/^(CY)([0-59]\d{7}[A-Z])$/},czech_republic:{multipliers:[8,7,6,5,4,3,2],lookup:[8,7,6,5,4,3,2,1,0,9,10],regex:/^(CZ)(\d{8,10})(\d{3})?$/,additional:[/^\d{8}$/,/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/,/^6\d{8}$/,/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/]},germany:{regex:/^(DE)([1-9]\d{8})$/},denmark:{multipliers:[2,7,6,5,4,3,2,1],regex:/^(DK)(\d{8})$/},estonia:{multipliers:[3,7,1,3,7,1,3,7],regex:/^(EE)(10\d{7})$/},greece:{multipliers:[256,128,64,32,16,8,4,2],regex:/^(EL)(\d{9})$/},spain:{multipliers:[2,1,2,1,2,1,2],regex:[/^(ES)([A-Z]\d{8})$/,/^(ES)([A-HN-SW]\d{7}[A-J])$/,/^(ES)([0-9YZ]\d{7}[A-Z])$/,/^(ES)([KLMX]\d{7}[A-Z])$/],additional:[/^[A-H|J|U|V]\d{8}$/,/^[A-H|N-S|W]\d{7}[A-J]$/,/^[0-9|Y|Z]\d{7}[A-Z]$/,/^[K|L|M|X]\d{7}[A-Z]$/]},europe:{regex:/^(EU)(\d{9})$/},finland:{multipliers:[7,9,10,5,8,4,2],regex:/^(FI)(\d{8})$/},france:{regex:[/^(FR)(\d{11})$/,/^(FR)([A-HJ-NP-Z]\d{10})$/,/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,/^(FR)([A-HJ-NP-Z]{2}\d{9})$/]},united_kingdom:{multipliers:[8,7,6,5,4,3,2],regex:[/^(GB)?(\d{9})$/,/^(GB)?(\d{12})$/,/^(GB)?(GD\d{3})$/,/^(GB)?(HA\d{3})$/]},croatia:{regex:/^(HR)(\d{11})$/},hungary:{multipliers:[9,7,3,1,9,7,3],regex:/^(HU)(\d{8})$/},ireland:{multipliers:[8,7,6,5,4,3,2],regex:[/^(IE)(\d{7}[A-W])$/,/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,/^(IE)(\d{7}[A-W][AH])$/]},italy:{multipliers:[1,2,1,2,1,2,1,2,1,2],regex:/^(IT)(\d{11})$/},latvia:{multipliers:[9,1,4,8,3,10,2,5,7,6],regex:/^(LV)(\d{11})$/},lithunia:{multipliers:{"short":[3,4,5,6,7,8,9,1],med:[1,2,3,4,5,6,7,8,9,1,2],alt:[3,4,5,6,7,8,9,1,2,3,4]},regex:/^(LT)(\d{9}|\d{12})$/},luxembourg:{regex:/^(LU)(\d{8})$/},malta:{multipliers:[3,4,6,7,8,9],regex:/^(MT)([1-9]\d{7})$/},netherlands:{multipliers:[9,8,7,6,5,4,3,2],regex:/^(NL)(\d{9})B\d{2}$/},norway:{multipliers:[3,2,7,6,5,4,3,2],regex:/^(NO)(\d{9})$/},poland:{multipliers:[6,5,7,2,3,4,5,6,7],regex:/^(PL)(\d{10})$/},portugal:{multipliers:[9,8,7,6,5,4,3,2],regex:/^(PT)(\d{9})$/},romania:{multipliers:[7,5,3,2,1,7,5,3,2],regex:/^(RO)([1-9]\d{1,9})$/},russia:{multipliers:{m_1:[2,4,10,3,5,9,4,6,8,0],m_2:[7,2,4,10,3,5,9,4,6,8,0],m_3:[3,7,2,4,10,3,5,9,4,6,8,0]},regex:/^(RU)(\d{10}|\d{12})$/},serbia:{regex:/^(RS)(\d{9})$/},slovenia:{multipliers:[8,7,6,5,4,3,2],regex:/^(SI)([1-9]\d{7})$/},slovakia_republic:{regex:/^(SK)([1-9]\d[2346-9]\d{7})$/},sweden:{regex:/^(SE)(\d{10}01)$/}},n={checkVAT:function(r){if(!r)return!1;r=r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"");for(var e in a)if(a.hasOwnProperty(e)){var i=a[e].regex;if(Array.isArray(i)){for(var l=0;l<i.length;l++)if(t(r,i[l],e))return!0}else if(t(r,i,e))return!0}return!1}},u={austria:function(r,e){for(var t=0,n=0;7>n;n++)l=r.charAt(n)*a[e].multipliers[n],t+=l>9?Math.floor(l/10)+l%10:l;return t=10-(t+4)%10,10===t&&(t=0),i=+r.slice(7,8),t===i},belgium:function(r,e){if(9===r.length&&(r="0"+r),0===+r.slice(1,2))return!1;var t=97-+r.slice(0,8)%97;return i=+r.slice(8,10),t===i},bulgaria:function(r,e){var t=function(){var e=0;l=0;for(var t=0;8>t;t++)l+=+r.charAt(t)*(t+1);if(e=l%11,10!==e)return i=+r.slice(8),e===i;l=0;for(var a=0;8>a;a++)l+=+r.charAt(a)*(a+3);return e=l%11,10===e&&(e=0),i=+r.slice(8),e===i},n=function(){var t=0;if(/^\d\d[0-5]\d[0-3]\d\d{4}$/.test(r)){var i=+r.slice(2,4);if(i>0&&13>i||i>20&&33>i||i>40&&53>i){t=0;for(var l=0;9>l;l++)t+=+r.charAt(l)*a[e].multipliers.physical[l];if(t%=11,10===t&&(t=0),t===+r.substr(9,1))return!0}}return!1},u=function(){var t=0;t=0;for(var i=0;9>i;i++)t+=+r.charAt(i)*a[e].multipliers.foreigner[i];return t%10===+r.substr(9,1)?!0:void 0},s=function(){var t=0;t=0;for(var l=0;9>l;l++)t+=+r.charAt(l)*a[e].multipliers.miscellaneous[l];return t=11-t%11,10===t?!1:(11===t&&(t=0),i=+r.substr(9,1),t===i)};return 9===r.length?t():n()||u()||s()},switzerland:function(r,e){for(var t=0,l=0;8>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=11-t%11,10===t?!1:(11===t&&(t=0),i=+r.substr(8,1),t===i)},cyprus:function(r,e){var t=0;if(12===+r.slice(0,2))return!1;for(var l=0;8>l;l++){var a=+r.charAt(l);if(l%2===0)switch(a){case 0:a=1;break;case 1:a=0;break;case 2:a=5;break;case 3:a=7;break;case 4:a=9;break;default:a=2*a+3}t+=a}return t%=26,t=String.fromCharCode(t+65),i=r.substr(8,1),t===i},czech_republic:function(r,e){var t=0;if(a[e].additional[0].test(r)){for(var l=0;7>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=11-t%11,10===t&&(t=0),11===t&&(t=1),i=+r.slice(7,8),t===i}if(a[e].additional[2].test(r)){for(var n=0;7>n;n++)t+=+r.charAt(n+1)*a[e].multipliers[n];return t=11-t%11,10===t&&(t=0),11===t&&(t=1),i=+r.slice(8,9),a[e].lookup[t-1]===i}if(a[e].additional[3].test(r)){var u=+r.slice(0,2)+r.slice(2,4)+r.slice(4,6)+r.slice(6,8)+r.slice(8);return i=+r%11===0,!(u%11!==0||!i)}return!1},germany:function(r,e){for(var t=10,l=0,a=0,n=0;8>n;n++)l=(+r.charAt(n)+t)%10,0===l&&(l=10),t=2*l%11;return a=11-t===10?0:11-t,i=+r.slice(8,9),a===i},denmark:function(r,e){for(var t=0,i=0;8>i;i++)t+=+r.charAt(i)*a[e].multipliers[i];return t%11===0},estonia:function(r,e){for(var t=0,l=0;8>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=10-t%10,10===t&&(t=0),i=+r.slice(8,9),t===i},greece:function(r,e){var t=0;8===r.length&&(r="0"+r);for(var l=0;8>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t%=11,t>9&&(t=0),i=+r.slice(8,9),t===i},spain:function(r,e){var t=0,n=0;if(a[e].additional[0].test(r)){for(t=0;7>t;t++)l=r.charAt(t+1)*a[e].multipliers[t],n+=l>9?Math.floor(l/10)+l%10:l;return n=10-n%10,10===n&&(n=0),i=+r.slice(8,9),n===i}if(a[e].additional[1].test(r)){for(t=0;7>t;t++)l=r.charAt(t+1)*a[e].multipliers[t],n+=l>9?Math.floor(l/10)+l%10:l;return n=10-n%10,n=String.fromCharCode(n+64),i=r.slice(8,9),n===i}if(a[e].additional[2].test(r)){var u=r;return"Y"===u.substring(0,1)&&(u=u.replace(/Y/,"1")),"Z"===u.substring(0,1)&&(u=u.replace(/Z/,"2")),i="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+u.substring(0,8)%23),u.charAt(8)===i}return a[e].additional[3].test(r)?(i="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+r.substring(1,8)%23),r.charAt(8)===i):!1},europe:function(){return!0},finland:function(r,e){for(var t=0,l=0;7>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=11-t%11,t>9&&(t=0),i=+r.slice(7,8),t===i},france:function(r,e){var t=0;return/^\d{11}$/.test(r)?(t=+r.substring(2),t=(100*t+12)%97,i=+r.slice(0,2),t===i):!0},united_kingdom:function(r,e){var t=0;if("GD"===r.substr(0,2))return i=500,r.substr(2,3)<i;if("HA"===r.substr(0,2))return i=499,r.substr(2,3)>i;if(0===+r.slice(0))return!1;for(var l=+r.slice(0,7),n=0;7>n;n++)t+=+r.charAt(n)*a[e].multipliers[n];for(var u=t;u>0;)u-=97;return u=Math.abs(u),u===+r.slice(7,9)&&9990001>l&&(1e5>l||l>999999)&&(9490001>l||l>97e5)?!0:(u>=55?u-=55:u+=42,i=+r.slice(7,9),!!(u===i&&l>1e6))},croatia:function(r,e){for(var t=10,l=0,a=0;10>a;a++)l=(+r.charAt(a)+t)%10,0===l&&(l=10),t=2*l%11;return i=+r.slice(10,11),(t+i)%10===1},hungary:function(r,e){for(var t=0,l=0;7>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=10-t%10,10===t&&(t=0),i=+r.slice(7,8),t===i},ireland:function(r,e){var t=0;/^\d[A-Z\*\+]/.test(r)&&(r="0"+r.substring(2,7)+r.substring(0,1)+r.substring(7,8));for(var l=0;7>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return/^\d{7}[A-Z][AH]$/.test(r)&&(t+="H"===r.charAt(8)?72:9),t%=23,t=0===t?"W":String.fromCharCode(t+64),i=r.slice(7,8),t===i},italy:function(r,e){var t=0;if(0===+r.slice(0,7))return!1;if(l=+r.slice(7,10),1>l||l>201&&999!==l&&888!==l)return!1;for(var n=0;10>n;n++)l=+r.charAt(n)*a[e].multipliers[n],t+=l>9?Math.floor(l/10)+l%10:l;return t=10-t%10,t>9&&(t=0),i=+r.slice(10,11),t===i},lithunia:function(r,e){var t=0;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;t=0;for(var l=0;8>l;l++)t+=+r.charAt(l)*(l+1);if(t%11===10){t=0;for(var n=0;8>n;n++)t+=+r.charAt(n)*a[e].multipliers["short"][n]}return t%=11,10===t&&(t=0),i=+r.slice(8,9),t===i}if(!/^\d{10}1/.test(r))return!1;t=0;for(var u=0;11>u;u++)t+=+r.charAt(u)*a[e].multipliers.med[u];if(t%11===10){t=0;for(var s=0;11>s;s++)t+=+r.charAt(s)*a[e].multipliers.alt[s]}return t%=11,10===t&&(t=0),i=+r.slice(11,12),t===i},luxembourg:function(r,e){var t=+r.slice(6,8),i=+r.slice(0,6)%89;return i===t},latvia:function(r,e){var t=0;if(/^[0-3]/.test(r))return!!/^[0-3][0-9][0-1][0-9]/.test(r);for(var l=0;10>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t%11===4&&9===r[0]&&(t-=45),t%11===4?t=4-t%11:t%11>4?t=14-t%11:4>t%11&&(t=3-t%11),i=+r.slice(10,11),t===i},malta:function(r,e){for(var t=0,l=0;6>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=37-t%37,i=+r.slice(6,8),t===i},netherlands:function(r,e){for(var t=0,l=0;8>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t%=11,t>9&&(t=0),i=+r.slice(8,9),t===i},norway:function(r,e){for(var t=0,l=0;8>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=11-t%11,11===t&&(t=0),10>t?(i=+r.slice(8,9),t===i):void 0},poland:function(r,e){for(var t=0,l=0;9>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t%=11,t>9&&(t=0),i=+r.slice(9,10),t===i},portugal:function(r,e){for(var t=0,l=0;8>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=11-t%11,t>9&&(t=0),i=+r.slice(8,9),t===i},romania:function(r,e){for(var t=0,l=r.length,n=a[e].multipliers.slice(10-l),u=0;u<r.length-1;u++)t+=+r.charAt(u)*n[u];return t=10*t%11,10===t&&(t=0),i=+r.slice(r.length-1,r.length),t===i},serbia:function(r,e){for(var t,l=10,a=0,n=0;8>n;n++)a=(+r.charAt(n)+l)%10,0===a&&(a=10),l=2*a%11;return i=1,t=(l+ +r.slice(8,9))%10,t===i},russia:function(r,e){var t,l=0;if(10===r.length){for(var n=0;10>n;n++)l+=+r.charAt(n)*a[e].multipliers.m_1[n];return l%=11,l>9&&(l%=10),i=+r.slice(9,10),l===i}if(12===r.length){for(var u=0,s=0,c=0;11>c;c++)u+=+r.charAt(c)*a[e].multipliers.m_2[c];u%=11,u>9&&(u%=10);for(var o=0;11>o;o++)s+=+r.charAt(o)*a[e].multipliers.m_3[o];return s%=11,s>9&&(s%=10),i=u===+r.slice(10,11),t=s===+r.slice(11,12),i&&t}},sweden:function(r,e){for(var t,l=0,a=0;9>a;a+=2)t=+r.charAt(a),l+=Math.floor(t/5)+2*t%10;for(var n=0,u=1;9>u;u+=2)n+=+r.charAt(u);var s=(10-(l+n)%10)%10;return i=+r.slice(9,10),s===i},slovenia:function(r,e){for(var t=0,l=0;7>l;l++)t+=+r.charAt(l)*a[e].multipliers[l];return t=11-t%11,10===t&&(t=0),i=+r.slice(7,8),!(11===t||t!==i)},slovakia_republic:function(r,e){var t=0,i=r%11;return i===t}};return"object"==typeof module&&module.exports&&(module.exports=n),n}();
//# sourceMappingURL=jsvat.min.js.map
{
"name": "jsvat",
"version": "0.4.8",
"version": "0.6.0",
"description": "Check the validity of the format of an EU VAT number",

@@ -40,3 +40,3 @@ "main": "./dist/jsvat.js",

"devDependencies": {
"chai": "^3.4.1",
"chai": "^3.5.0",
"gulp-buddy.js": "^1.0.0",

@@ -47,9 +47,10 @@ "gulp-filesize": "0.0.6",

"gulp-sourcemaps": "^1.6.0",
"gulp-todo": "^4.0.0",
"gulp-uglify": "^1.4.2",
"gulp-todo": "^4.1.0",
"gulp-uglify": "^1.5.3",
"gulp-watch": "^4.3.5",
"gulp-wrap": "^0.11.0",
"jshint-stylish": "^2.0.1",
"mocha": "^2.3.4"
"jshint": "^2.9.1",
"jshint-stylish": "^2.1.0",
"mocha": "^2.4.5"
}
}
var jsvat = (function () {
'use strict';
'use strict';
var _REGEXP_LIST = {
austria: /^(AT)U(\d{8})$/,
belgium: /^(BE)(0?\d{9})$/,
bulgaria: /^(BG)(\d{9,10})$/,
switzerland: /^(CHE)(\d{9})(MWST)?$/,
cyprus: /^(CY)([0-59]\d{7}[A-Z])$/,
czech_republic: /^(CZ)(\d{8,10})(\d{3})?$/,
germany: /^(DE)([1-9]\d{8})$/,
denmark: /^(DK)(\d{8})$/,
estonia: /^(EE)(10\d{7})$/,
greece: /^(EL)(\d{9})$/,
spain: [
/^(ES)([A-Z]\d{8})$/,
/^(ES)([A-HN-SW]\d{7}[A-J])$/,
/^(ES)([0-9YZ]\d{7}[A-Z])$/,
/^(ES)([KLMX]\d{7}[A-Z])$/
],
europe: /^(EU)(\d{9})$/,
finland: /^(FI)(\d{8})$/,
france: [
/^(FR)(\d{11})$/,
/^(FR)([A-HJ-NP-Z]\d{10})$/,
/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,
/^(FR)([A-HJ-NP-Z]{2}\d{9})$/
],
united_kingdom: [
/^(GB)?(\d{9})$/,
/^(GB)?(\d{12})$/,
/^(GB)?(GD\d{3})$/,
/^(GB)?(HA\d{3})$/
],
croatia: /^(HR)(\d{11})$/,
hungary: /^(HU)(\d{8})$/,
ireland: [
/^(IE)(\d{7}[A-W])$/,
/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,
/^(IE)(\d{7}[A-W][AH])$/
],
italy: /^(IT)(\d{11})$/,
latvia: /^(LV)(\d{11})$/,
lithunia: /^(LT)(\d{9}|\d{12})$/,
luxembourg: /^(LU)(\d{8})$/,
malta: /^(MT)([1-9]\d{7})$/,
netherlands: /^(NL)(\d{9})B\d{2}$/,
norway: /^(NO)(\d{9})$/,
poland: /^(PL)(\d{10})$/,
portugal: /^(PT)(\d{9})$/,
romania: /^(RO)([1-9]\d{1,9})$/,
russia: /^(RU)(\d{10}|\d{12})$/,
serbia: /^(RS)(\d{9})$/,
slovenia: /^(SI)([1-9]\d{7})$/,
slovakia_republic: /^(SK)([1-9]\d[2346-9]\d{7})$/,
sweden: /^(SE)(\d{10}01)$/
};
var CONDITIONS = {
austria: {
multipliers: [1, 2, 1, 2, 1, 2, 1],
regex: /^(AT)U(\d{8})$/
},
belgium: {
regex: /^(BE)(0?\d{9})$/
},
bulgaria: {
multipliers: {
physical: [2, 4, 8, 5, 10, 9, 7, 3, 6],
foreigner: [21, 19, 17, 13, 11, 9, 7, 3, 1],
miscellaneous: [4, 3, 2, 7, 6, 5, 4, 3, 2]
},
regex: /^(BG)(\d{9,10})$/
},
switzerland: {
multipliers: [5, 4, 3, 2, 7, 6, 5, 4],
regex: /^(CHE)(\d{9})(MWST)?$/
},
cyprus: {
regex: /^(CY)([0-59]\d{7}[A-Z])$/
},
czech_republic: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
lookup: [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10],
regex: /^(CZ)(\d{8,10})(\d{3})?$/,
additional: [
/^\d{8}$/,
/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/,
/^6\d{8}$/,
/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/
]
},
germany: {
regex: /^(DE)([1-9]\d{8})$/
},
denmark: {
multipliers: [2, 7, 6, 5, 4, 3, 2, 1],
regex: /^(DK)(\d{8})$/
},
estonia: {
multipliers: [3, 7, 1, 3, 7, 1, 3, 7],
regex: /^(EE)(10\d{7})$/
},
greece: {
multipliers: [256, 128, 64, 32, 16, 8, 4, 2],
regex: /^(EL)(\d{9})$/
},
spain: {
multipliers: [2, 1, 2, 1, 2, 1, 2],
regex: [
/^(ES)([A-Z]\d{8})$/,
/^(ES)([A-HN-SW]\d{7}[A-J])$/,
/^(ES)([0-9YZ]\d{7}[A-Z])$/,
/^(ES)([KLMX]\d{7}[A-Z])$/
],
additional: [
/^[A-H|J|U|V]\d{8}$/,
/^[A-H|N-S|W]\d{7}[A-J]$/,
/^[0-9|Y|Z]\d{7}[A-Z]$/,
/^[K|L|M|X]\d{7}[A-Z]$/
]
},
europe: {
regex: /^(EU)(\d{9})$/
},
finland: {
multipliers: [7, 9, 10, 5, 8, 4, 2],
regex: /^(FI)(\d{8})$/
},
france: {
regex: [
/^(FR)(\d{11})$/,
/^(FR)([A-HJ-NP-Z]\d{10})$/,
/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,
/^(FR)([A-HJ-NP-Z]{2}\d{9})$/
]
function _validateRegexp(vat, regexp) {
return regexp.test(vat);
}
},
united_kingdom: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [
/^(GB)?(\d{9})$/,
/^(GB)?(\d{12})$/,
/^(GB)?(GD\d{3})$/,
/^(GB)?(HA\d{3})$/
]
function _validateRules(vat, regexp, countryName) {
var parsedNum = regexp.exec(vat);
},
croatia: {
regex: /^(HR)(\d{11})$/
},
hungary: {
multipliers: [9, 7, 3, 1, 9, 7, 3],
regex: /^(HU)(\d{8})$/
},
ireland: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [
/^(IE)(\d{7}[A-W])$/,
/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,
/^(IE)(\d{7}[A-W][AH])$/
]
//var code = parsedNum[1];
var number = parsedNum[2];
//if (!code || code.length === 0) code = 'GB';
return _checks[countryName](number);
},
italy: {
multipliers: [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],
regex: /^(IT)(\d{11})$/
},
latvia: {
multipliers: [9, 1, 4, 8, 3, 10, 2, 5, 7, 6],
regex: /^(LV)(\d{11})$/
},
lithunia: {
multipliers: {
short: [3, 4, 5, 6, 7, 8, 9, 1],
med: [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2],
alt: [3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4]
},
regex: /^(LT)(\d{9}|\d{12})$/
},
luxembourg: {
regex: /^(LU)(\d{8})$/
},
malta: {
multipliers: [3, 4, 6, 7, 8, 9],
regex: /^(MT)([1-9]\d{7})$/
},
netherlands: {
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: /^(NL)(\d{9})B\d{2}$/
},
norway: {
multipliers: [3, 2, 7, 6, 5, 4, 3, 2],
regex: /^(NO)(\d{9})$/
},
poland: {
multipliers: [6, 5, 7, 2, 3, 4, 5, 6, 7],
regex: /^(PL)(\d{10})$/
},
portugal: {
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: /^(PT)(\d{9})$/
},
romania: {
multipliers: [7, 5, 3, 2, 1, 7, 5, 3, 2],
regex: /^(RO)([1-9]\d{1,9})$/
},
russia: {
multipliers: {
m_1: [2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
m_2: [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
m_3: [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0]
},
regex: /^(RU)(\d{10}|\d{12})$/
},
serbia: {
regex: /^(RS)(\d{9})$/
},
slovenia: {
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: /^(SI)([1-9]\d{7})$/
},
slovakia_republic: {
regex: /^(SK)([1-9]\d[2346-9]\d{7})$/
},
sweden: {
regex: /^(SE)(\d{10}01)$/
}
};
function _validate(vat, regexp, countryName) {
var result = false;
if (_validateRegexp(vat, regexp)) {
result = _validateRules(vat, regexp, countryName);
}
return result;
}
function _validateRegex(vat, regex) {
return regex.test(vat);
}
var exports = {
checkVAT: function (vat) {
if (!vat) return false;
vat = vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
function _validateRules(vat, regex, countryName) {
var parsedNum = regex.exec(vat);
for (var countryName in _REGEXP_LIST) {
if (_REGEXP_LIST.hasOwnProperty(countryName)) {
var regexp = _REGEXP_LIST[countryName];
//var code = parsedNum[1];
var number = parsedNum[2];
//if (!code || code.length === 0) code = 'GB';
//TODO (S.Panfilov) this is not cross-browser check
if (Array.isArray(regexp)) {
for (var i = 0; i < regexp.length; i++) {
if (_validate(vat, regexp[i], countryName)) return true;
}
} else {
if (_validate(vat, regexp, countryName)) return true;
}
}
}
return false;
return _checks[countryName](number, countryName);
}
}
};
function _validate(vat, regex, countryName) {
var result = false;
if (_validateRegex(vat, regex)) {
result = _validateRules(vat, regex, countryName);
}
return result;
}
var _checks = {
austria: function (vat) {
var total = 0;
var multipliers = [1, 2, 1, 2, 1, 2, 1];
var temp;
var expect;
var exports = {
checkVAT: function (vat) {
if (!vat) return false;
vat = vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
for (var i = 0; i < 7; i++) {
temp = vat.charAt(i) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
for (var countryName in CONDITIONS) {
if (CONDITIONS.hasOwnProperty(countryName)) {
var regex = CONDITIONS[countryName].regex;
total = 10 - (total + 4) % 10;
if (total === 10) total = 0;
expect = +vat.slice(7, 8);
return total === expect;
},
belgium: function (vat) {
var expect;
var check;
if (vat.length === 9) vat = "0" + vat;
if (+vat.slice(1, 2) === 0) return false;
check = (97 - +vat.slice(0, 8) % 97);
expect = +vat.slice(8, 10);
return check === expect;
},
bulgaria: function (vat) {
var expect;
var multipliers;
var temp;
var total;
var checkNineLengthVat = function () {
temp = 0;
for (var i = 0; i < 8; i++) {
temp += +vat.charAt(i) * (i + 1);
}
total = temp % 11;
if (total !== 10) {
expect = +vat.slice(8);
return total === expect;
}
temp = 0;
for (var j = 0; j < 8; j++) {
temp += +vat.charAt(j) * (j + 3);
}
total = temp % 11;
if (total === 10) total = 0;
expect = +vat.slice(8);
return total === expect;
};
var isPhysicalPerson = function () {
// 10 digit VAT code - see if it relates to a standard physical person
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
// Check month
var month = +vat.slice(2, 4);
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
// Extract the next digit and multiply by the counter.
multipliers = [2, 4, 8, 5, 10, 9, 7, 3, 6];
total = 0;
for (var k = 0; k < 9; k++) {
total += +vat.charAt(k) * multipliers[k];
}
// Establish check digit.
total = total % 11;
if (total === 10) total = 0;
// Check to see if the check digit given is correct, If not, try next type of person
if (total === +vat.substr(9, 1)) return true;
}
}
return false;
};
// It doesn't relate to a standard physical person - see if it relates to a foreigner.
var isForeigner = function () {
// Extract the next digit and multiply by the counter.
multipliers = [21, 19, 17, 13, 11, 9, 7, 3, 1];
total = 0;
for (var l = 0; l < 9; l++) {
total += +vat.charAt(l) * multipliers[l];
}
// Check to see if the check digit given is correct, If not, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true;
}
};
var miscellaneousVAT = function () {
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
// Extract the next digit and multiply by the counter.
multipliers = [4, 3, 2, 7, 6, 5, 4, 3, 2];
total = 0;
for (var m = 0; m < 9; m++) {
total += +vat.charAt(m) * multipliers[m];
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(9, 1);
return total === expect;
};
if (vat.length === 9) {
return checkNineLengthVat();
} else {
return isPhysicalPerson() || isForeigner() || miscellaneousVAT();
//TODO (S.Panfilov) this is not cross-browser check
if (Array.isArray(regex)) {
for (var i = 0; i < regex.length; i++) {
if (_validate(vat, regex[i], countryName)) return true;
}
} else {
if (_validate(vat, regex, countryName)) return true;
}
}
}
return false;
},
switzerland: function (vat) {
var expect;
}
};
// Checks the check digits of a Swiss VAT number.
var expect;
var temp;
// Extract the next digit and multiply by the counter.
var multipliers = [5, 4, 3, 2, 7, 6, 5, 4];
var total = 0;
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
var _checks = {
austria: function (vat, countryName) {
var total = 0;
for (var i = 0; i < 7; i++) {
temp = vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
total = 10 - (total + 4) % 10;
if (total === 10) total = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(8, 1);
return total === expect;
},
cyprus: function (vat) {
var expect;
expect = +vat.slice(7, 8);
// Checks the check digits of a Cypriot VAT number.
return total === expect;
},
belgium: function (vat, countryName) {
if (vat.length === 9) vat = "0" + vat;
if (+vat.slice(1, 2) === 0) return false;
// Not allowed to start with '12'
if (+vat.slice(0, 2) === 12) return false;
var check = (97 - +vat.slice(0, 8) % 97);
expect = +vat.slice(8, 10);
return check === expect;
},
bulgaria: function (vat, countryName) {
var checkNineLengthVat = function () {
var total = 0;
temp = 0;
for (var i = 0; i < 8; i++) {
temp += +vat.charAt(i) * (i + 1);
}
// Extract the next digit and multiply by the counter.
var total = 0;
for (var i = 0; i < 8; i++) {
var temp = +vat.charAt(i);
if (i % 2 === 0) {
switch (temp) {
case 0:
temp = 1;
break;
case 1:
temp = 0;
break;
case 2:
temp = 5;
break;
case 3:
temp = 7;
break;
case 4:
temp = 9;
break;
default:
temp = temp * 2 + 3;
}
}
total += temp;
}
total = temp % 11;
if (total !== 10) {
expect = +vat.slice(8);
return total === expect;
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
temp = 0;
for (var j = 0; j < 8; j++) {
temp += +vat.charAt(j) * (j + 3);
}
// Check to see if the check digit given is correct
expect = vat.substr(8, 1);
return total === expect;
},
czech_republic: function (vat) {
var expect;
total = temp % 11;
if (total === 10) total = 0;
expect = +vat.slice(8);
// Checks the check digits of a Czech Republic VAT number.
return total === expect;
};
var total = 0;
var multipliers = [8, 7, 6, 5, 4, 3, 2];
var isPhysicalPerson = function () {
var total = 0;
// 10 digit VAT code - see if it relates to a standard physical person
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
// Check month
var month = +vat.slice(2, 4);
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var czExp = [];
czExp[0] = (/^\d{8}$/);
czExp[1] = (/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/);
czExp[2] = (/^6\d{8}$/);
czExp[3] = (/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/);
// Legal entities
if (czExp[0].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * multipliers[i];
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
total = 0;
for (var k = 0; k < 9; k++) {
total += +vat.charAt(k) * CONDITIONS[countryName].multipliers.physical[k];
}
// Individuals type 1
//else if (czExp[1].test(vat)) {
//TODO (S.Panfilov) It's seems to be an error
// return !(temp = +vat.slice(0, 2) > 53);
//
//}
// Individuals type 2
else if (czExp[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var j = 0; j < 7; j++) {
total += +vat.charAt(j + 1) * multipliers[j];
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Convert calculated check digit according to a lookup table;
var lookup = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10];
expect = +vat.slice(8, 9);
return lookup[total - 1] === expect;
}
// Individuals type 3
else if (czExp[3].test(vat)) {
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8);
expect = +vat % 11 === 0;
return !!(temp % 11 === 0 && expect);
}
// else error
return false;
},
germany: function (vat) {
var expect;
// Checks the check digits of a German VAT number.
var product = 10;
var sum = 0;
var checkDigit = 0;
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement peculiar algorithm!.
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
// Establish check digit.
if (11 - product === 10) {
checkDigit = 0;
} else {
checkDigit = 11 - product;
}
// Compare it with the last two characters of the VAT number. If the same, then it is a valid
// check digit.
expect = +vat.slice(8, 9);
return checkDigit === expect;
},
denmark: function (vat) {
var total = 0;
var multipliers = [2, 7, 6, 5, 4, 3, 2, 1];
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
return total % 11 === 0;
},
estonia: function (vat) {
var expect;
// Checks the check digits of an Estonian VAT number.
var total = 0;
var multipliers = [3, 7, 1, 3, 7, 1, 3, 7];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits using modulus 10.
total = 10 - total % 10;
total = total % 11;
if (total === 10) total = 0;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
greece: function (vat) {
var expect;
// Check to see if the check digit given is correct, If not, try next type of person
if (total === +vat.substr(9, 1)) return true;
}
}
// Checks the check digits of a Greek VAT number.
return false;
var total = 0;
var multipliers = [256, 128, 64, 32, 16, 8, 4, 2];
};
//eight character numbers should be prefixed with an 0.
if (vat.length === 8) {
vat = "0" + vat;
}
// It doesn't relate to a standard physical person - see if it relates to a foreigner.
var isForeigner = function () {
var total = 0;
// Extract the next digit and multiply by the counter.
total = 0;
for (var l = 0; l < 9; l++) {
total += +vat.charAt(l) * CONDITIONS[countryName].multipliers.foreigner[l];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Check to see if the check digit given is correct, If not, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true;
}
};
// Establish check digit.
total = total % 11;
if (total > 9) {
total = 0;
}
var miscellaneousVAT = function () {
var total = 0;
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
spain: function (vat) {
var expect;
total = 0;
for (var m = 0; m < 9; m++) {
total += +vat.charAt(m) * CONDITIONS[countryName].multipliers.miscellaneous[m];
}
// Checks the check digits of a Spanish VAT number.
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
var total = 0;
var temp = 0;
var multipliers = [2, 1, 2, 1, 2, 1, 2];
var esExp = [];
esExp[0] = (/^[A-H|J|U|V]\d{8}$/);
esExp[1] = (/^[A-H|N-S|W]\d{7}[A-J]$/);
esExp[2] = (/^[0-9|Y|Z]\d{7}[A-Z]$/);
esExp[3] = (/^[K|L|M|X]\d{7}[A-Z]$/);
var i = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(9, 1);
return total === expect;
};
// National juridical entities
if (esExp[0].test(vat)) {
if (vat.length === 9) {
return checkNineLengthVat();
} else {
return isPhysicalPerson() || isForeigner() || miscellaneousVAT();
}
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Now calculate the check digit itself.
total = 10 - total % 10;
if (total === 10) {
total = 0;
}
},
switzerland: function (vat, countryName) {
var total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
// Juridical entities other than national ones
else if (esExp[1].test(vat)) {
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
expect = +vat.substr(8, 1);
return total === expect;
},
cyprus: function (vat, countryName) {
var total = 0;
// Not allowed to start with '12'
if (+vat.slice(0, 2) === 12) return false;
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Extract the next digit and multiply by the counter.
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total + 64);
for (var i = 0; i < 8; i++) {
var temp = +vat.charAt(i);
if (i % 2 === 0) {
switch (temp) {
case 0:
temp = 1;
break;
case 1:
temp = 0;
break;
case 2:
temp = 5;
break;
case 3:
temp = 7;
break;
case 4:
temp = 9;
break;
default:
temp = temp * 2 + 3;
}
}
total += temp;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(8, 9);
return total === expect;
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
// Personal number (NIF) (starting with numeric of Y or Z)
else if (esExp[2].test(vat)) {
var tempnumber = vat;
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, "1");
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, "2");
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23);
return tempnumber.charAt(8) === expect;
}
// Check to see if the check digit given is correct
expect = vat.substr(8, 1);
return total === expect;
},
czech_republic: function (vat, countryName) {
var total = 0;
// Personal number (NIF) (starting with K, L, M, or X)
else if (esExp[3].test(vat)) {
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23);
return vat.charAt(8) === expect;
}
// Legal entities
if (CONDITIONS[countryName].additional[0].test(vat)) {
else return false;
},
europe: function () {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// We know little about EU numbers apart from the fact that the first 3 digits represent the
// country, and that there are nine digits in total.
return true;
},
finland: function (vat) {
var expect;
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Checks the check digits of a Finnish VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
}
var total = 0;
var multipliers = [7, 9, 10, 5, 8, 4, 2];
// Individuals type 2
else if (CONDITIONS[countryName].additional[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Extract the next digit and multiply by the counter.
for (var j = 0; j < 7; j++) {
total += +vat.charAt(j + 1) * CONDITIONS[countryName].multipliers[j];
}
// Establish check digit.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
france: function (vat) {
var expect;
// Convert calculated check digit according to a lookup table;
expect = +vat.slice(8, 9);
return CONDITIONS[countryName].lookup[total - 1] === expect;
}
// Checks the check digits of a French VAT number.
// Individuals type 3
else if (CONDITIONS[countryName].additional[3].test(vat)) {
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8);
expect = +vat % 11 === 0;
return !!(temp % 11 === 0 && expect);
}
if (!(/^\d{11}$/).test(vat)) {
return true;
}
// else error
return false;
},
germany: function (vat, countryName) {
// Extract the last nine digits as an integer.
var total = +vat.substring(2);
// Establish check digit.
total = (total * 100 + 12) % 97;
// Checks the check digits of a German VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(0, 2);
return total === expect;
},
united_kingdom: function (vat) {
var expect;
var product = 10;
var sum = 0;
var checkDigit = 0;
for (var i = 0; i < 8; i++) {
// Checks the check digits of a UK VAT number.
// Extract the next digit and implement peculiar algorithm!.
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
var multipliers = [8, 7, 6, 5, 4, 3, 2];
// Establish check digit.
if (11 - product === 10) {
checkDigit = 0;
} else {
checkDigit = 11 - product;
}
// Government departments
if (vat.substr(0, 2) === 'GD') {
expect = 500;
return vat.substr(2, 3) < expect;
}
// Compare it with the last two characters of the VAT number. If the same, then it is a valid
// check digit.
expect = +vat.slice(8, 9);
return checkDigit === expect;
},
denmark: function (vat, countryName) {
var total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Health authorities
if (vat.substr(0, 2) === 'HA') {
expect = 499;
return vat.substr(2, 3) > expect;
}
return total % 11 === 0;
},
estonia: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Standard and commercial numbers
var total = 0;
// Establish check digits using modulus 10.
total = 10 - total % 10;
if (total === 10) total = 0;
// 0 VAT numbers disallowed!
if (+vat.slice(0) === 0) return false;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
greece: function (vat, countryName) {
var total = 0;
//eight character numbers should be prefixed with an 0.
if (vat.length === 8) {
vat = "0" + vat;
}
// Check range is OK for modulus 97 calculation
var no = +vat.slice(0, 7);
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digit.
total = total % 11;
if (total > 9) {
total = 0;
}
// Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our
// VAT number could use either system, so we check it against both.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
spain: function (vat, countryName) {
var i = 0;
var total = 0;
// Establish check digits by subtracting 97 from total until negative.
var checkDigit = total;
while (checkDigit > 0) {
checkDigit = checkDigit - 97;
}
// National juridical entities
if (CONDITIONS[countryName].additional[0].test(vat)) {
// Get the absolute value and compare it with the last two characters of the VAT number. If the
// same, then it is a valid traditional check digit. However, even then the number must fit within
// certain specified ranges.
checkDigit = Math.abs(checkDigit);
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Now calculate the check digit itself.
total = 10 - total % 10;
if (total === 10) {
total = 0;
}
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (checkDigit >= 55)
checkDigit = checkDigit - 55;
else
checkDigit = checkDigit + 42;
expect = +vat.slice(7, 9);
return !!(checkDigit === expect && no > 1000000);
},
croatia: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
// Juridical entities other than national ones
else if (CONDITIONS[countryName].additional[1].test(vat)) {
var product = 10;
var sum = 0;
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
for (var i = 0; i < 10; i++) {
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total + 64);
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(8, 9);
return total === expect;
}
product = (2 * sum) % 11;
}
// Personal number (NIF) (starting with numeric of Y or Z)
else if (CONDITIONS[countryName].additional[2].test(vat)) {
var tempnumber = vat;
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, "1");
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, "2");
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23);
return tempnumber.charAt(8) === expect;
}
// Now check that we have the right check digit
expect = +vat.slice(10, 11);
return (product + expect) % 10 === 1;
},
hungary: function (vat) {
var expect;
// Personal number (NIF) (starting with K, L, M, or X)
else if (CONDITIONS[countryName].additional[3].test(vat)) {
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23);
return vat.charAt(8) === expect;
}
// Checks the check digits of a Hungarian VAT number.
else return false;
},
europe: function () {
//TODO (S.Panfilov) wtf?
// We know little about EU numbers apart from the fact that the first 3 digits represent the
// country, and that there are nine digits in total.
return true;
},
finland: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
var total = 0;
var multipliers = [9, 7, 3, 1, 9, 7, 3];
// Establish check digit.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
france: function (vat, countryName) {
var total = 0;
// Checks the check digits of a French VAT number.
if (!(/^\d{11}$/).test(vat)) {
return true;
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10) total = 0;
// Extract the last nine digits as an integer.
total = +vat.substring(2);
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
ireland: function (vat) {
var expect;
// Establish check digit.
total = (total * 100 + 12) % 97;
// Checks the check digits of an Irish VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(0, 2);
return total === expect;
},
united_kingdom: function (vat, countryName) {
var total = 0;
// Government departments
if (vat.substr(0, 2) === 'GD') {
expect = 500;
return vat.substr(2, 3) < expect;
}
var total = 0;
var multipliers = [8, 7, 6, 5, 4, 3, 2];
// Health authorities
if (vat.substr(0, 2) === 'HA') {
expect = 499;
return vat.substr(2, 3) > expect;
}
// If the code is type 1 format, we need to convert it to the new before performing the validation.
if (/^\d[A-Z\*\+]/.test(vat)) {
vat = "0" + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8);
}
// Standard and commercial numbers
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * multipliers[i];
}
// If the number is type 3 then we need to include the trailing A or H in the calculation
if (/^\d{7}[A-Z][AH]$/.test(vat)) {
// Add in a multiplier for the character A (1*9=9) or H (8*9=72)
if (vat.charAt(8) === 'H') {
total += 72;
} else {
total += 9;
}
}
// 0 VAT numbers disallowed!
if (+vat.slice(0) === 0) return false;
// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
if (total === 0) {
total = "W";
} else {
total = String.fromCharCode(total + 64);
}
// Check range is OK for modulus 97 calculation
var no = +vat.slice(0, 7);
// Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(7, 8);
return total === expect;
},
italy: function (vat) {
var expect;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Checks the check digits of an Italian VAT number.
// Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our
// VAT number could use either system, so we check it against both.
var total = 0;
var multipliers = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
var temp;
// Establish check digits by subtracting 97 from total until negative.
var checkDigit = total;
while (checkDigit > 0) {
checkDigit = checkDigit - 97;
}
// The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
if (+vat.slice(0, 7) === 0) {
return false;
}
// Get the absolute value and compare it with the last two characters of the VAT number. If the
// same, then it is a valid traditional check digit. However, even then the number must fit within
// certain specified ranges.
checkDigit = Math.abs(checkDigit);
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
temp = +vat.slice(7, 10);
if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
return false;
}
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (checkDigit >= 55)
checkDigit = checkDigit - 55;
else
checkDigit = checkDigit + 42;
expect = +vat.slice(7, 9);
return !!(checkDigit === expect && no > 1000000);
},
croatia: function (vat, countryName) {
// Extract the next digit and multiply by the appropriate
for (var i = 0; i < 10; i++) {
temp = +vat.charAt(i) * multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Establish check digit.
total = 10 - total % 10;
if (total > 9) {
total = 0;
}
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
},
lithunia: function (vat) {
var total;
var multipliers;
var expect;
var product = 10;
var sum = 0;
// Checks the check digits of a Lithuanian VAT number.
for (var i = 0; i < 10; i++) {
// 9 character VAT numbers are for legal persons
if (vat.length === 9) {
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false;
product = (2 * sum) % 11;
}
// Extract the next digit and multiply by the counter+1.
total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1);
}
// Now check that we have the right check digit
expect = +vat.slice(10, 11);
return (product + expect) % 10 === 1;
},
hungary: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Can have a double check digit calculation!
if (total % 11 === 10) {
multipliers = [3, 4, 5, 6, 7, 8, 9, 1];
total = 0;
for (var j = 0; j < 8; j++) {
total += +vat.charAt(j) * multipliers[j];
}
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10) total = 0;
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
},
ireland: function (vat, countryName) {
var total = 0;
// If the code is type 1 format, we need to convert it to the new before performing the validation.
if (/^\d[A-Z\*\+]/.test(vat)) {
vat = "0" + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8);
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// 12 character VAT numbers are for temporarily registered taxpayers
else {
// If the number is type 3 then we need to include the trailing A or H in the calculation
if (/^\d{7}[A-Z][AH]$/.test(vat)) {
// Add in a multiplier for the character A (1*9=9) or H (8*9=72)
if (vat.charAt(8) === 'H') {
total += 72;
} else {
total += 9;
}
}
// 11th character must be one
if (!(/^\d{10}1/).test(vat)) return false;
// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
if (total === 0) {
total = "W";
} else {
total = String.fromCharCode(total + 64);
}
// Extract the next digit and multiply by the counter+1.
total = 0;
multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2];
for (var k = 0; k < 11; k++) {
total += +vat.charAt(k) * multipliers[k];
}
// Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(7, 8);
return total === expect;
},
italy: function (vat, countryName) {
var total = 0;
// The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
if (+vat.slice(0, 7) === 0) {
return false;
}
// Can have a double check digit calculation!
if (total % 11 === 10) {
multipliers = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4];
total = 0;
for (var l = 0; l < 11; l++) {
total += +vat.charAt(l) * multipliers[l];
}
}
temp = +vat.slice(7, 10);
if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
return false;
}
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Extract the next digit and multiply by the appropriate
for (var i = 0; i < 10; i++) {
temp = +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
else
total += temp;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(11, 12);
return total === expect;
}
},
luxembourg: function (vat) {
var expect = +vat.slice(6, 8);
var checkDigit = +vat.slice(0, 6) % 89;
// Checks the check digits of a Luxembourg VAT number.
// Establish check digit.
total = 10 - total % 10;
if (total > 9) {
total = 0;
}
return checkDigit === expect;
},
latvia: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
},
lithunia: function (vat, countryName) {
var total = 0;
// 9 character VAT numbers are for legal persons
if (vat.length === 9) {
// Checks the check digits of a Latvian VAT number.
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false;
// Differentiate between legal entities and natural bodies. For the latter we simply check that
// the first six digits correspond to valid DDMMYY dates.
if ((/^[0-3]/).test(vat)) {
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat);
} else {
// Extract the next digit and multiply by the counter+1.
total = 0;
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1);
}
var total = 0;
var multipliers = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6];
// Can have a double check digit calculation!
if (total % 11 === 10) {
total = 0;
for (var j = 0; j < 8; j++) {
total += +vat.charAt(j) * CONDITIONS[countryName].multipliers.short[j];
}
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Establish check digits by getting modulus 11.
if (total % 11 === 4 && vat[0] === 9) total = total - 45;
if (total % 11 === 4)
total = 4 - total % 11;
else if (total % 11 > 4)
total = 14 - total % 11;
else if (total % 11 < 4)
total = 3 - total % 11;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
}
},
malta: function (vat) {
var expect;
// 12 character VAT numbers are for temporarily registered taxpayers
else {
// Checks the check digits of a Maltese VAT number.
// 11th character must be one
if (!(/^\d{10}1/).test(vat)) return false;
var total = 0;
var multipliers = [3, 4, 6, 7, 8, 9];
// Extract the next digit and multiply by the counter+1.
total = 0;
for (var k = 0; k < 11; k++) {
total += +vat.charAt(k) * CONDITIONS[countryName].multipliers.med[k];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) total += +vat.charAt(i) * multipliers[i];
// Can have a double check digit calculation!
if (total % 11 === 10) {
total = 0;
for (var l = 0; l < 11; l++) {
total += +vat.charAt(l) * CONDITIONS[countryName].multipliers.alt[l];
}
}
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
// Establish check digit.
total = total % 11;
if (total === 10) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(6, 8);
return total === expect;
},
netherlands: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(11, 12);
return total === expect;
}
},
luxembourg: function (vat, countryName) {
var expect = +vat.slice(6, 8);
var checkDigit = +vat.slice(0, 6) % 89;
// Checks the check digits of a Luxembourg VAT number.
// Checks the check digits of a Dutch VAT number.
return checkDigit === expect;
},
latvia: function (vat, countryName) {
var total = 0;
var total = 0;
var multipliers = [9, 8, 7, 6, 5, 4, 3, 2];
// Differentiate between legal entities and natural bodies. For the latter we simply check that
// the first six digits correspond to valid DDMMYY dates.
if ((/^[0-3]/).test(vat)) {
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat);
} else {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Establish check digits by getting modulus 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Establish check digits by getting modulus 11.
if (total % 11 === 4 && vat[0] === 9) total = total - 45;
if (total % 11 === 4)
total = 4 - total % 11;
else if (total % 11 > 4)
total = 14 - total % 11;
else if (total % 11 < 4)
total = 3 - total % 11;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
norway: function (vat) {
var expect;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
}
},
malta: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Checks the check digits of a Norwegian VAT number.
// See http://www.brreg.no/english/coordination/number.html
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
var total = 0;
var multipliers = [3, 2, 7, 6, 5, 4, 3, 2];
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(6, 8);
return total === expect;
},
netherlands: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits by getting modulus 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Establish check digits by getting modulus 11. Check digits > 9 are invalid
total = 11 - total % 11;
if (total === 11) {
total = 0;
}
if (total < 10) {
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
norway: function (vat, countryName) {
var total = 0;
// See http://www.brreg.no/english/coordination/number.html
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
},
poland: function (vat) {
var expect;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Checks the check digits of a Polish VAT number.
// Establish check digits by getting modulus 11. Check digits > 9 are invalid
total = 11 - total % 11;
if (total === 11) {
total = 0;
}
if (total < 10) {
var total = 0;
var multipliers = [6, 5, 7, 2, 3, 4, 5, 6, 7];
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
}
},
poland: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
if (total > 9) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return total === expect;
},
portugal: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return total === expect;
},
portugal: function (vat) {
var expect;
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Checks the check digits of a Portugese VAT number.
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
romania: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
var vatLength = vat.length;
var multipliers = CONDITIONS[countryName].multipliers.slice(10 - vatLength);
var total = 0;
var multipliers = [9, 8, 7, 6, 5, 4, 3, 2];
for (var i = 0; i < vat.length - 1; i++) {
total += +vat.charAt(i) * multipliers[i];
}
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total === 10) total = 0;
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(vat.length - 1, vat.length);
return total === expect;
},
serbia: function (vat, countryName) {
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
},
romania: function (vat) {
var expect;
// Checks the check digits of a Romanian VAT number.
// Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.
var multipliers = [7, 5, 3, 2, 1, 7, 5, 3, 2];
var product = 10;
var sum = 0;
var checkDigit;
// Extract the next digit and multiply by the counter.
var vatLength = vat.length;
multipliers = multipliers.slice(10 - vatLength);
var total = 0;
for (var i = 0; i < vat.length - 1; i++) {
total += +vat.charAt(i) * multipliers[i];
}
for (var i = 0; i < 8; i++) {
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total === 10) total = 0;
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(vat.length - 1, vat.length);
return total === expect;
},
serbia: function (vat) {
var expect;
// Now check that we have the right check digit
expect = 1;
checkDigit = (product + (+vat.slice(8, 9))) % 10;
return checkDigit === expect;
},
russia: function (vat, countryName) {
var total = 0;
var expect2;
// Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.
// Checks the check digits of a Russian INN number
// See http://russianpartner.biz/test_inn.html for algorithm
var product = 10;
var sum = 0;
var checkDigit;
// 10 digit INN numbers
if (vat.length === 10) {
for (var i = 0; i < 8; i++) {
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers.m_1[i];
}
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
if (sum === 0) {
sum = 10;
}
product = (2 * sum) % 11;
}
total = total % 11;
if (total > 9) {
total = total % 10;
}
// Now check that we have the right check digit
expect = 1;
checkDigit = (product + (+vat.slice(8, 9))) % 10;
return checkDigit === expect;
},
russia: function (vat) {
var expect;
var expect2;
// Compare it with the last character of the VAT number. If it is the same, then it's valid
expect = +vat.slice(9, 10);
return total === expect;
// Checks the check digits of a Russian INN number
// See http://russianpartner.biz/test_inn.html for algorithm
// 12 digit INN numbers
} else if (vat.length === 12) {
var total1 = 0;
var total2 = 0;
// 10 digit INN numbers
if (vat.length === 10) {
var total = 0;
var multipliers = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * multipliers[i];
}
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * CONDITIONS[countryName].multipliers.m_2[j];
}
total = total % 11;
if (total > 9) {
total = total % 10;
}
total1 = total1 % 11;
if (total1 > 9) {
total1 = total1 % 10;
}
// Compare it with the last character of the VAT number. If it is the same, then it's valid
expect = +vat.slice(9, 10);
return total === expect;
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * CONDITIONS[countryName].multipliers.m_3[k];
}
// 12 digit INN numbers
} else if (vat.length === 12) {
var total1 = 0;
var multipliers1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
var total2 = 0;
var multipliers2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
total2 = total2 % 11;
if (total2 > 9) {
total2 = total2 % 10;
}
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * multipliers1[j];
}
// Compare the first check with the 11th character and the second check with the 12th and last
// character of the VAT number. If they're both the same, then it's valid
//expect = +vat.slice(10, 11);
expect = (total1 === +vat.slice(10, 11));
//expect2 = +vat.slice(11, 12);
expect2 = (total2 === +vat.slice(11, 12));
return (expect) && (expect2);
}
},
sweden: function (vat, countryName) {
// Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
var R = 0;
var digit;
for (var i = 0; i < 9; i = i + 2) {
digit = +vat.charAt(i);
R += Math.floor(digit / 5) + ((digit * 2) % 10);
}
total1 = total1 % 11;
if (total1 > 9) {
total1 = total1 % 10;
}
// Calculate S where S = C2 + C4 + C6 + C8
var S = 0;
for (var j = 1; j < 9; j = j + 2) {
S += +vat.charAt(j);
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * multipliers2[k];
}
var checkDigit = (10 - (R + S) % 10) % 10;
total2 = total2 % 11;
if (total2 > 9) {
total2 = total2 % 10;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
// Compare the first check with the 11th character and the second check with the 12th and last
// character of the VAT number. If they're both the same, then it's valid
expect = +vat.slice(10, 11);
expect2 = +vat.slice(11, 12);
return (expect) && (expect2);
}
},
sweden: function (vat) {
var expect;
return checkDigit === expect;
},
slovenia: function (vat, countryName) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * CONDITIONS[countryName].multipliers[i];
}
// Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
var R = 0;
var digit;
for (var i = 0; i < 9; i = i + 2) {
digit = +vat.charAt(i);
R += Math.floor(digit / 5) + ((digit * 2) % 10);
}
// Establish check digits using modulus 11
total = 11 - total % 11;
if (total === 10) {
total = 0;
}
// Calculate S where S = C2 + C4 + C6 + C8
var S = 0;
for (var j = 1; j < 9; j = j + 2) {
S += +vat.charAt(j);
}
// Compare the number with the last character of the VAT number. If it is the
// same, then it's a valid check digit.
expect = +vat.slice(7, 8);
return !!(total !== 11 && total === expect);
},
slovakia_republic: function (vat, countryName) {
var expect = 0;
var checkDigit = (vat % 11);
// Checks the check digits of a Slovakian VAT number.
// Check that the modulus of the whole VAT number is 0 - else error
return checkDigit === expect;
}
};
var checkDigit = (10 - (R + S) % 10) % 10;
if (typeof module === 'object' && module.exports) module.exports = exports;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return checkDigit === expect;
},
slovenia: function (vat) {
var expect;
// Checks the check digits of a Slovenian VAT number.
var total = 0;
var multipliers = [8, 7, 6, 5, 4, 3, 2];
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * multipliers[i];
// Establish check digits using modulus 11
total = 11 - total % 11;
if (total === 10) {
total = 0;
}
// Compare the number with the last character of the VAT number. If it is the
// same, then it's a valid check digit.
expect = +vat.slice(7, 8);
return !!(total !== 11 && total === expect);
},
slovakia_republic: function (vat) {
var expect = 0;
var checkDigit = (vat % 11);
// Checks the check digits of a Slovakian VAT number.
// Check that the modulus of the whole VAT number is 0 - else error
return checkDigit === expect;
}
};
if (typeof module === 'object' && module.exports) module.exports = exports;
return exports;
return exports;
})();
### TODOs
| Filename | line # | TODO
|:------|:------:|:------
| jsvat.js | 90 | (S.Panfilov) this is not cross-browser check
| jsvat.js | 333 | (S.Panfilov) It's seems to be an error
| jsvat.js | 207 | (S.Panfilov) this is not cross-browser check
| jsvat.js | 588 | (S.Panfilov) wtf?

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc