1/*================================================================================================== 2 3Application: Utility Function 4Author: John Gardner 5Website: https://www.braemoor.co.uk/software/vat.shtml 6 7Version: V1.0 8Date: 30th July 2005 9Description: Used to check the validity of an EU country VAT number 10 11Version: V1.1 12Date: 3rd August 2005 13Description: Lithuanian legal entities & Maltese check digit checks added. 14 15Version: V1.2 16Date: 20th October 2005 17Description: Italian checks refined (thanks Matteo Mike Peluso). 18 19Version: V1.3 20Date: 16th November 2005 21Description: Error in GB numbers ending in 00 fixed (thanks Guy Dawson). 22 23Version: V1.4 24Date: 28th September 2006 25Description: EU-type numbers added. 26 27Version: V1.5 28Date: 1st January 2007 29Description: Romanian and Bulgarian numbers added. 30 31Version: V1.6 32Date: 7th January 2007 33Description: Error with Slovenian numbers (thanks to Ales Hotko). 34 35Version: V1.7 36Date: 10th February 2007 37Description: Romanian check digits added. 38 Thanks to Dragu Costel for the test suite. 39 40Version: V1.8 41Date: 3rd August 2007 42Description: IE code modified to allow + and * in old format numbers. 43 Thanks to Antonin Moy of Sphere Solutions for pointing out the error. 44 45Version: V1.9 46Date: 6th August 2007 47Description: BE code modified to make a specific check that the leading character of 10 digit 48 numbers is 0 (belts and braces). 49 50Version: V1.10 51Date: 10th August 2007 52Description: Cypriot check digit support added. 53 Check digit validation support for non-standard UK numbers 54 55Version: V1.11 56Date: 25th September 2007 57Description: Spain check digit support for personal numbers. 58 Author: David Perez Carmona 59 60Version: V1.12 61Date: 23rd November 2009 62Description: GB code modified to take into account new style check digits. 63 Thanks to Guy Dawson of Crossflight Ltd for pointing out the necessity. 64 65Version: V1.13 66Date: 7th July 2012 67Description: EL, GB, SE and BE formats updated - thanks to Joost Van Biervliet of VAT Applications 68 69Version: V.14 70Date: 8th April 2013 71Description: BE Pattern match refined 72 BG Add check digit checks for all four types of VAT number 73 CY Pattern match improved 74 CZ Personal pattern match checking improved 75 CZ Personal check digits incorporated 76 EE improved pattern match 77 ES Physical person number checking refined 78 GB Check digit support provided for 12 digit VAT codes and range checks included 79 IT Bug removed to allow 999 and 888 issuing office codes 80 LT temporarily registered taxpayers check digit support added 81 LV Natural persons checks added 82 RO improved pattern match 83 SK improved pattern match and added check digit support 84 85 Thanks to Theo Vroom for his help in this latest release. 86 87Version: V1.15 88Date: 15th April 2013 89 Swedish algorithm re-implemented. 90 91Version: V1.16 92Date: 25th July 2013 93 Support for Croatian numbers added 94 95Version V1.17 96 10th September 2013 97 Support for Norwegian MVA numbers added (yes, I know that Norway is not in the EU!) 98 99Version V1.18 100 29th October 2013 101 Partial support for new style Irish numbers. 102 See http://www.revenue.ie/en/practitioner/ebrief/2013/no-032013.html 103 Thanks to Simon Leigh for drawing the author's attention to this. 104 105Version V1.19 106 31st October 2013 107 Support for Serbian PBI numbers added (yes, I know that Serbia is not in the EU!) 108 109Version V1.20 110 1st November 2013 111 Support for Swiss MWST numbers added (yes, I know that Switzerland is not in the EU!) 112 113Version V1.21 114 16th December 2014 115 Non-critical code tidies to French and Danish regular expressions. 116 Thanks to Bill Seddon of Lyquidity Solutions 117 118Version V1.22 119 14th January 2014 120 Non-critical code tidy to regular expression for new format Irish numbers. 121 Thanks to Olivier Reubens of UNIT4 C-Logic N.V. 122 123Version V1.23 124 10th April 2014 125 Support for Russian INN numbers added (yes, I know that Ru
125ssia is not in the EU!). 126 Thanks to Marco Cesaratto of Arki Tech, Italy 127 128Version V1.24 129 4th June 2014 130 Check digit validation supported for Irish Type 3 numbers 131 Thanks to Olivier Reubens of UNIT4 C-Logic N.V. 132 133Version V1.25 134 29th July 2014 135 Code improvements 136 Thanks to Sébastien Boelpaep and Nate Kerkhofs 137 138Version V1.26 139 4th May 2015 140 Code improvements to regular expressions 141 Thanks to Robert Gust-Bardon of webcraft.ch 142 143Version V1.27 144 3rd December 2015 145 Extend Swiss optional suffix to allow TVA and ITA 146 Thanks to Oskars Petermanis 147 148Version V1.28 149 30th August 2016 150 Correct Swiss optional suffix to allow TVA and IVA 151 Thanks to Jan Verhaegen 152 153Version V1.29 154 29th July 2017 155 Correct Czeck Republic checking of Individual type 2 - Special Cases 156 Thanks to Andreas Wuermser of Auer Packaging UK 157 158Version V1.30 159 06 December 2019 160 Support for new sole proprietor traders added to Dutch validation 161 Thanks to Olivier Reubens of UNIT4 C-Logic N.V. 162 163Version V1.31 164 19 January 2020 165 Correction to the new sole proprietor traders added to Dutch validation 166 Thanks to Bill Seddon of Lyquidity Solutions 167 168Version V1.32 169 23 January 2020 170 Updated to reflect new Belgium VAT format (minor difference) 171 Thanks to A. Roland Wintgen, EVG Elektro-Vertriebs-Gesellschaft Martens GmbH & Co. KG 172 173Version V1.33 174 9 June 2020 175 Updated to refine pattern matching of first 2 characters of Portuguese numbers 176 Thanks to Alann Jaksnon 177 178Version V1.34 179 11 December 2020 180 Correction to Dutch validation - Thanks to Olivier Reubens of UNIT4 C-Logic N.V. 181 Addition of UK Northern Ireland protocols (XI) 182 183Version V1.35 184 20 December 2020 185 Code tidy 186 187Version V1.36 188 30 December 2020 189 Addition of Israeli VAT numbers, Australian ABN numbers and Brazilian CNPJ numbers 190 191Parameters: toCheck - VAT number be checked. 192 193This function checks the value of the parameter for a valid European VAT number. 194 195If the number is found to be invalid format, the function returns a value of false. Otherwise it 196returns the VAT number re-formatted. 197 198Example call: 199 200 if (checkVATNumber (myVATNumber)) 201 alert ("VAT number has a valid format") 202 else 203 alert ("VAT number has invalid format"); 204 205---------------------------------------------------------------------------------------------------*/ 206 207function checkVATNumber (toCheck) { 208 209 // To change the default country (e.g. from the UK to Germany - DE): 210 // 1. Change the country code in the defCCode variable below to "DE". 211 // 2. Remove the question mark from the regular expressions associated with the UK VAT number: 212 // i.e. "(GB)?" -> "(GB)" 213 // 3. Add a question mark into the regular expression associated with Germany's number 214 // following the country code: i.e. "(DE)" -> "(DE)?" 215 216 var defCCode = "GB"; 217 218 // Array holds the regular expressions for the national VAT formats 219 var vatexp = []; 220 221 // Note - VAT codes without the "**" in the comment do not have check digit checking. 222 223 vatexp.push (/^(AT)U(\d{8})$/); //** Austria 224 vatexp.push (/^(AU|ABN:?)(\d{11})(\d{3})?$/); //** Australia (non EU) - allow ABN 225 vatexp.push (/^(BE)(0?\d{9})$/); //** Belgium 226 vatexp.push (/^(BE)([0-1]\d{9})$/); //** Belgium - since 01/01/2020 227 vatexp.push (/^(BR|CNPJ)[:|\.]?\s?(\d{2}\.?\d{3}\.?\d{3}\.?\/?\d{4}-?\d{2})$/); //** Brazil 228 vatexp.push (/^(BG)(\d{9,10})$/); //** Bulgaria 229 vatexp.push (/^(CHE)(\d{9})(MWST|TVA|IVA)?$/); //** Switzerland 230 vatexp.push (/^(CY)([0-59]\d{7}[A-Z])$/); //** Cyprus 231 vatexp.push (/^(CZ)(\d{8,10})(\d{3})?$/); //** Czech Republic 232 vatexp.push (/^(DE)([1-9]\d{8})$/); //** Germany 233 vatexp.push (/^(DK)(\d{8})$/); //** Denmark 234 vatexp.push (/^(EE)(10\d{7})$/); //** Estonia 235 vatexp.push (/^(EL|GR)(\d{9})$/); //** Greece 236 vatexp.push (/^(ES)([A-Z]\d{8})$/); //** Spain (National juridical entities) 237 vatexp.push (/^(ES)([A-HN-SW]\d{7}[A-J])$/); //** Spain (Other juridical entities) 238 vatexp.push (/^(ES)([0-9YZ]\d{7}[A-Z])$/);
238 //** Spain (Personal entities type 1) 239 vatexp.push (/^(ES)([KLMX]\d{7}[A-Z])$/); //** Spain (Personal entities type 2) 240 vatexp.push (/^(EU)(\d{9})$/); //** EU-type 241 vatexp.push (/^(FI)(\d{8})$/); //** Finland 242 vatexp.push (/^(FR)(\d{11})$/); //** France (1) 243 vatexp.push (/^(FR)([A-HJ-NP-Z]\d{10})$/); // France (2) 244 vatexp.push (/^(FR)(\d[A-HJ-NP-Z]\d{9})$/); // France (3) 245 vatexp.push (/^(FR)([A-HJ-NP-Z]{2}\d{9})$/); // France (4) 246 vatexp.push (/^(GB|XI)?(\d{9})$/); //** UK (Standard) (not EU) 247 vatexp.push (/^(GB|XI)?(\d{12})$/); //** UK (Branches) (not EU) 248 vatexp.push (/^(GB|XI)?(GD\d{3})$/); //** UK (Government) (not EU) 249 vatexp.push (/^(GB|XI)?(HA\d{3})$/); //** UK (Health authority) (not EU) 250 vatexp.push (/^(HR)(\d{11})$/); //** Croatia 251 vatexp.push (/^(HU)(\d{8})$/); //** Hungary 252 vatexp.push (/^(IE)(\d{7}[A-W])$/); //** Ireland (1) 253 vatexp.push (/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/); //** Ireland (2) 254 vatexp.push (/^(IE)(\d{7}[A-W][AH])$/); //** Ireland (3) 255 vatexp.push (/^(IL)(\d{2,9})$/); //** Israel (not EU) 256 vatexp.push (/^(IT)(\d{11})$/); //** Italy 257 vatexp.push (/^(LV)(\d{11})$/); //** Latvia 258 vatexp.push (/^(LT)(\d{9}|\d{12})$/); //** Lithuania 259 vatexp.push (/^(LU)(\d{8})$/); //** Luxembourg 260 vatexp.push (/^(MT)([1-9]\d{7})$/); //** Malta 261 vatexp.push (/^(NL)(\d{9}B\d{2})$/); //** Netherlands 262 vatexp.push (/^(NL)([A-Z0-9\*\+]{10}\d{2})$/); //** Netherlands sole proprietor 263 vatexp.push (/^(NO)(\d{9})$/); //** Norway (not EU) 264 vatexp.push (/^(PL)(\d{10})$/); //** Poland 265 vatexp.push (/^(PT)(((([1-3]|5|6)\d)|(45)|(7([0-2]|[4-5]|[7-9]))|(9[0|1|8|9]))(\d{7}$))/); //** Portugal 266 vatexp.push (/^(RO)([1-9]\d{1,9})$/); //** Romania 267 vatexp.push (/^(RS)(\d{9})$/); //** Serbia 268 vatexp.push (/^(RU)(\d{10}|\d{12})$/); //** Russia (not EU) 269 vatexp.push (/^(SE)(\d{10}01)$/); //** Sweden 270 vatexp.push (/^(SI)([1-9]\d{7})$/); //** Slovenia 271 vatexp.push (/^(SK)([1-9]\d[2346-9]\d{7})$/); //** Slovakia Republic 272 273 // Load up the string to check, converting it top uppercase 274 var VATNumber = toCheck.toUpperCase(); 275 276 // Remove spaces etc. from the VAT number to help validation 277 VATNumber = VATNumber.replace (/(\s|-|\.|\/)+/g, ''); 278 279 // Assume we're not going to find a valid VAT number 280 var valid = false; 281 282 // Check the string against the regular expressions for all types of VAT numbers 283 for (var i=0; i<vatexp.length; i++) { 284 285 // Have we recognised the VAT number? 286 if (vatexp[i].test(VATNumber)) { 287 288 // Yes - we have - remember the important elements, setting up the default county code if 289 // necessary. 290 var cCode = (RegExp.$1.length == 0) ? defCCode : RegExp.$1; // The country code 291 var cNumber = RegExp.$2; // The number 292 293 // Alternative country codes need converting to create the routine name 294 switch (cCode.slice(0,4)) { 295 case "ABN": cCode = "AU"; break; // Australia 296 case "CNPJ": cCode = "BR"; break; // Brazil 297 case "GR": cCode = "EL"; break; // Greece 298 case "XI": cCode = "GB"; break; // Northern Ireland 299 default: break; 300 } 301 302 // Call the appropriate country VAT validation routine depending on the country code. The 303 // function name is "VATCheckDigit" prefixed by the country code, and is called with a 304 // parameter of the VAT number without the country code: 305 // e.g. GBVATCheckDigit (vatNumber) 306 if (eval(cCode+"VATCheckDigit ('"+cNumber+"')")) valid = VATNumber; 307 308 // Having processed the number, we break from the loop 309 break; 310 } 311 } 312 313 // Return with either an error or the reformatted VAT number 314 return valid; 315} 316 317function ATVATCheckDigit (vatnumber) { 318 319 // Validates an Austrian VAT number. 320 321 var total = 0; 322 var multipliers = [1,2,1,2,1,2,1];
323 var temp = 0; 324 325 // Extract the next digit and multiply by the appropriate multiplier. 326 for (var i = 0; i < 7; i++) { 327 temp = Number (vatnumber.charAt(i)) * multipliers[i]; 328 if (temp > 9) 329 total += Math.floor(temp/10) + temp%10; 330 else 331 total += temp; 332 } 333 334 // Establish check digit. 335 total = 10 - (total+4) % 10; 336 if (total == 10) total = 0; 337 338 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 339 if (total == vatnumber.slice (7,8)) 340 return true; 341 else 342 return false; 343} 344 345function AUVATCheckDigit (vatnumber) { 346 347 // Validates an Australian VAT number. 348 349 // Multipliers for a MOD 89 calculation 350 var multipliers = [10,1,3,5,7,9,11,13,15,17,19]; 351 352 // Take one away from the first digit character 353 vatnumber = vatnumber.split(''); 354 vatnumber[0] = String.fromCharCode(vatnumber[0].charCodeAt() - 1); 355 vatnumber = vatnumber.join(''); 356 357 // Calculate the total based on multiplying each digit by its equivalent multiplier 358 var total = 0; 359 for (var i = 0; i < 11; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
360 361 // If the remainder when divided by 89 is 0, then it is valid 362 if (total % 89 == 0) 363 return true; 364 else 365 return false; 366} 367 368function BEVATCheckDigit (vatnumber) { 369 370 // Validates a Belgium VAT number. 371 372 // Nine digit numbers have a 0 inserted at the front. 373 if (vatnumber.length == 9) vatnumber = "0" + vatnumber; 374 375 if (vatnumber.slice(1,2) == 0) return false; 376 377 // Perform a modulus 97 calculation on the first 8 digits - the last two digits should be the same 378 if (97 - vatnumber.slice (0,8) % 97 == vatnumber.slice (8)) 379 return true; 380 else 381 return false; 382} 383 384function BGVATCheckDigit (vatnumber) { 385 386 // Validates a Bulgarian VAT number. 387 388 var total, i, temp; 389 var multipliers = []; 390 391 if (vatnumber.length == 9) { 392 393 // Check the check digit of 9 digit Bulgarian VAT numbers. 394 total = 0; 395 396 // First try to calculate the check digit using the first multipliers 397 temp = 0; 398 for (i = 0; i < 8; i++) temp += Number(vatnumber.charAt(i)) * (i+1); 399 400 // See if we have a check digit yet 401 total = temp % 11; 402 if (total != 10) { 403 if (total == vatnumber.slice (8)) 404 return true; 405 else 406 return false; 407 } 408 409 // We got a modulus of 10 before so we have to keep going. Calculate the new check digit using 410 // the different multipliers 411 temp = 0; 412 for (i = 0; i < 8; i++) temp += Number(vatnumber.charAt(i)) * (i+3); 413 414 // See if we have a check digit yet. If we still have a modulus of 10, set it to 0. 415 total = temp % 11; 416 if (total == 10) total = 0; 417 if (total == vatnumber.slice (8)) 418 return true; 419 else 420 return false; 421 } 422 423 // 10 digit VAT code - see if it relates to a standard physical person 424 if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vatnumber)) { 425 426 // Check month 427 var month = Number(vatnumber.slice(2,4)); 428 if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) { 429 430 // Extract the next digit and multiply by the counter. 431 multipliers = [2,4,8,5,10,9,7,3,6]; 432 total = 0; 433 for (i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
434 435 // Establish check digit. 436 total = total % 11; 437 if (total == 10) total = 0; 438 439 // Check to see if the check digit given is correct, If not, try next type of person 440 if (total == vatnumber.substr (9,1)) return true; 441 } 442 } 443 444 // It doesn't relate to a standard physical person - see if it relates to a foreigner. 445 446 // Extract the next digit and multiply by the counter. 447 multipliers = [21,19,17,13,11,9,7,3,1]; 448 total = 0; 449 for (i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 450 451 // Check to see if the check digit given is correct, If not, try next type of person 452 if (total % 10 == vatnumber.substr (9,1)) return true; 453 454 // Finally, if not yet identified, see if it conforms to a miscellaneous VAT number 455 456 // Extract the next digit and multiply by the counter. 457 multipliers = [4,3,2,7,6,5,4,3,2]; 458 total = 0; 459 for (i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 460 461 // Establish check digit. 462 total = 11 - total % 11; 463 if (total == 10) return false; 464 if (total == 11) total = 0; 465 466 // Check to see if the check digit given is correct, If not, we have an error with the VAT number 467 if (total == vatnumber.substr (9,1)) 468 return true; 469 else 470 return false; 471} 472 473function BRVATCheckDigit (vatnumber) { 474 475 // Validates an Brazilian CPNJ number. 476 // See https://www.cdq.ch/sites/default/files/CDQ_Data%20Quality%20Rule_for%20Brazil.pdf 477 478 // Multipliers for a MOD 89 calculation 479 var multipliers = [2,3,4,5,6,7,8,9,2,3,4,5,6]; 480 481 // Calculate the total based on multiplying the first 12 digits by their equivalent multiplier 482 var total = 0; 483 for (var i = 11; i > -1; i--) total += Number(vatnumber.charAt(i)) * multipliers[11-i]; 484 485 // Calculate the check digit for digit 13 486 var temp = total % 11; 487 if (temp == 0 || temp == 1) temp = 0; else temp = 11 - total % 11; 488 489 // Return if not valid 490 if (temp != Number(vatnumber.charAt(12))) return false; 491 492 // Repeat but include the first (correct) check digit in position 13 493 total = 0; 494 for (i = 12; i > -1; i--) total += Number(vatnumber.charAt(i)) * multipliers[12-i]; 495 496 // Calculate the check digit for digit 14 497 temp = total % 11; 498 if (temp == 0 || temp == 1) temp = 0; else temp = 11 - total % 11; 499 500 if (temp != Number(vatnumber.charAt(13))) 501 return false; 502 else 503 return true; 504} 505 506function CHEVATCheckDigit (vatnumber) { 507 508 // Validates a Swiss VAT number. 509 510 // Extract the next digit and multiply by the counter. 511 var multipliers = [5,4,3,2,7,6,5,4]; 512 var total = 0; 513 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
514 515 // Establish check digit. 516 total = 11 - total % 11; 517 if (total == 10) return false; 518 if (total == 11) total = 0; 519 520 // Check to see if the 9 digit given is the same as the check digit. If not, we have an error with the VAT number 521 if (total == vatnumber.slice (8)) 522 return true; 523 else 524 return false; 525} 526 527function CYVATCheckDigit (vatnumber) { 528 529 // Validates a Cypriot VAT number. 530 531 // Not allowed to start with '12' 532 if (Number(vatnumber.slice(0,2) == 12)) return false; 533 534 // Extract the next digit and multiply by the counter. 535 var total = 0; 536 for (var i = 0; i < 8; i++) { 537 var temp = Number(vatnumber.charAt(i)); 538 if (i % 2 == 0) { 539 switch (temp) { 540 case 0: temp = 1; break; 541 case 1: temp = 0; break; 542 case 2: temp = 5; break; 543 case 3: temp = 7; break; 544 case 4: temp = 9; break; 545 default: temp = temp*2 + 3; 546 } 547 } 548 total += temp; 549 } 550 551 // Establish check digit using modulus 26, and translate to char. equivalent. 552 total = total % 26; 553 total = String.fromCharCode(total+65); 554 555 // Check to see if the 9th digit is the check digit. If not, the VAT number is invalid 556 if (total == vatnumber.slice (8)) 557 return true; 558 else 559 return false; 560} 561 562function CZVATCheckDigit (vatnumber) { 563 564 // Validates a Czech Republic VAT number. 565 566 var total = 0; 567 var multipliers = [8,7,6,5,4,3,2]; 568 var i; 569 var a; 570 var temp; 571 572 var czexp = []; 573 czexp[0] = (/^\d{8}$/); // 8 digit legal entities 574 // Note - my specification says that that the following should have a range of 0-3 in the fourth 575 // digit, but the valid number CZ395601439 did not confirm, so a range of 0-9 has been allowed. 576 czexp[1] = (/^[0-5][0-9][0|1|5|6][0-9][0-3][0-9]\d{3}$/); // 9 digit individuals 577 czexp[2] = (/^6\d{8}$/); // 9 digit individuals (Special cases) 578 czexp[3] = (/^\d{2}[0-3|5-8][0-9][0-3][0-9]\d{4}$/); // 10 digit individuals 579 580 // Legal entities 581 if (czexp[0].test(vatnumber)) { 582 583 // Extract the next digit and multiply by the counter. 584 for (i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
585 586 // Establish check digit. 587 total = 11 - total % 11; 588 if (total == 10) total = 0; 589 if (total == 11) total = 1; 590 591 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 592 if (total == vatnumber.slice (7)) 593 return true; 594 else 595 return false; 596 } 597 598 // Individuals type 1 (Standard) - 9 digits without check digit 599 else if (czexp[1].test(vatnumber)) { 600 if (temp == Number(vatnumber.slice(0,2)) > 62) return false; 601 return true; 602 } 603 604 // Individuals type 2 (Special Cases) - 9 digits including check digit 605 else if (czexp[2].test(vatnumber)) { 606 607 // Extract the next digit and multiply by the counter. 608 for (i = 0; i < 7; i++) total += Number(vatnumber.charAt(i+1)) * multipliers[i]; 609 610 // Establish check digit pointer into lookup table 611 if (total % 11 == 0) 612 a = total + 11; 613 else 614 a = Math.ceil (total/11) * 11; 615 var pointer = a - total; 616 617 // Convert calculated check digit according to a lookup table; 618 var lookup = [8,7,6,5,4,3,2,1,0,9,8]; 619 if (lookup[pointer-1] == vatnumber.slice (8,9)) 620 return true; 621 else 622 return false; 623 } 624 625 // Individuals type 3 - 10 digits 626 else if (czexp[3].test(vatnumber)) { 627 temp = Number(vatnumber.slice(0,2)) + Number(vatnumber.slice(2,4)) + Number(vatnumber.slice(4,6)) + Number(vatnumber.slice(6,8)) + Number(vatnumber.slice(8)); 628 if (temp % 11 == 0 && Number(vatnumber) % 11 == 0) 629 return true; 630 else 631 return false; 632 } 633 634 // else error 635 return false; 636} 637 638function DEVATCheckDigit (vatnumber) { 639 640 // Validates a German VAT number. 641 642 var product = 10; 643 var sum = 0; 644 var checkdigit = 0; 645 for (var i = 0; i < 8; i++) { 646 647 // Extract the next digit and implement peculiar algorithm!. 648 sum = (Number(vatnumber.charAt(i)) + product) % 10; 649 if (sum == 0) sum = 10; 650 product = (2 * sum) % 11; 651 } 652 653 // Establish check digit. 654 if (11 - product == 10) checkdigit = 0; else checkdigit = 11 - product; 655 656 // Compare it with the last two characters of the VAT number. If the same, then it is a valid 657 // check digit. 658 if (checkdigit == vatnumber.slice (8)) 659 return true; 660 else 661 return false; 662} 663 664function DKVATCheckDigit (vatnumber) { 665 666 // Validates a Danish VAT number. 667 668 var total = 0; 669 var multipliers = [2,7,6,5,4,3,2,1]; 670 671 // Extract the next digit and multiply by the counter. 672 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
673 674 // Establish check digit. 675 total = total % 11; 676 677 // The remainder should be 0 for it to be valid.. 678 if (total == 0) 679 return true; 680 else 681 return false; 682} 683 684function EEVATCheckDigit (vatnumber) { 685 686 // Validates an Estonian VAT number. 687 688 var total = 0; 689 var multipliers = [3,7,1,3,7,1,3,7]; 690 691 // Extract the next digit and multiply by the counter. 692 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 693 694 // Establish check digits using modulus 10. 695 total = 10 - total % 10; 696 if (total == 10) total = 0; 697 698 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 699 if (total == vatnumber.slice (8)) 700 return true; 701 else 702 return false; 703} 704 705function ELVATCheckDigit (vatnumber) { 706 707 // Validates a Greek VAT number. 708 709 var total = 0; 710 var multipliers = [256,128,64,32,16,8,4,2]; 711 712 //eight character numbers should be prefixed with an 0. 713 if (vatnumber.length == 8) vatnumber = "0" + vatnumber; 714 715 // Extract the next digit and multiply by the counter. 716 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
717 718 // Establish check digit. 719 total = total % 11; 720 if (total > 9) total = 0; 721 722 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 723 if (total == vatnumber.slice (8)) 724 return true; 725 else 726 return false; 727} 728 729function ESVATCheckDigit (vatnumber) { 730 731 // Validates a Spanish VAT number. 732 733 var total = 0; 734 var temp = 0; 735 var multipliers = [2,1,2,1,2,1,2]; 736 var esexp = []; 737 esexp[0] = (/^[A-H|J|U|V]\d{8}$/); 738 esexp[1] = (/^[A-H|N-S|W]\d{7}[A-J]$/); 739 esexp[2] = (/^[0-9|Y|Z]\d{7}[A-Z]$/); 740 esexp[3] = (/^[K|L|M|X]\d{7}[A-Z]$/); 741 var i = 0; 742 743 // National juridical entities 744 if (esexp[0].test(vatnumber)) { 745 746 // Extract the next digit and multiply by the counter. 747 for (i = 0; i < 7; i++) { 748 temp = Number(vatnumber.charAt(i+1)) * multipliers[i]; 749 if (temp > 9) 750 total += Math.floor(temp/10) + temp%10; 751 else 752 total += temp; 753 } 754 // Now calculate the check digit itself. 755 total = 10 - total % 10; 756 if (total == 10) total = 0; 757 758 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 759 if (total == vatnumber.slice (8)) 760 return true; 761 else 762 return false; 763 } 764 765 // Juridical entities other than national ones 766 else if (esexp[1].test(vatnumber)) { 767 768 // Extract the next digit and multiply by the counter. 769 for (i = 0; i < 7; i++) { 770 temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
771 if (temp > 9) 772 total += Math.floor(temp/10) + temp%10; 773 else 774 total += temp; 775 } 776 777 // Now calculate the check digit itself. 778 total = 10 - total % 10; 779 total = String.fromCharCode(total+64); 780 781 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 782 if (total == vatnumber.slice (8)) 783 return true; 784 else 785 return false; 786 } 787 788 // Personal number (NIF) (starting with numeric of Y or Z) 789 else if (esexp[2].test(vatnumber)) { 790 var tempnumber = vatnumber; 791 if (tempnumber.substring(0,1) == 'Y') tempnumber = tempnumber.replace (/Y/, "1"); 792 if (tempnumber.substring(0,1) == 'Z') tempnumber = tempnumber.replace (/Z/, "2"); 793 return tempnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(tempnumber.substring(0,8)) % 23); 794 } 795 796 // Personal number (NIF) (starting with K, L, M, or X) 797 else if (esexp[3].test(vatnumber)) { 798 return vatnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(vatnumber.substring(1,8)) % 23); 799 } 800 801 else return false; 802} 803 804function EUVATCheckDigit (vatnumber) { 805 806 // Should Validates am EU VAT number. 807 808 // We know little about EU numbers apart from the fact that the first 3 digits represent the 809 // country, and that there are nine digits in total. 810 811 return true; 812} 813 814function FIVATCheckDigit (vatnumber) { 815 816 // Validates a Finnish VAT number. 817 818 var total = 0; 819 var multipliers = [7,9,10,5,8,4,2]; 820 821 // Extract the next digit and multiply by the counter. 822 for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
823 824 // Establish check digit. 825 total = 11 - total % 11; 826 if (total > 9) total = 0; 827 828 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 829 if (total == vatnumber.slice (7)) 830 return true; 831 else 832 return false; 833} 834 835function FRVATCheckDigit (vatnumber) { 836 837 // Validates a French VAT number. 838 839 if (!(/^\d{11}$/).test(vatnumber)) return true; 840 841 // Extract the last nine digits as an integer. 842 var total = vatnumber.substring(2); 843 844 // Establish check digit. 845 total = (total*100+12) % 97; 846 847 // Compare it with the first two character of the VAT number. If it's the same, then it's valid. 848 if (total == vatnumber.slice (0,2)) 849 return true; 850 else 851 return false; 852} 853 854function GBVATCheckDigit (vatnumber) { 855 856 // Validates a UK VAT number. 857 858 var multipliers = [8,7,6,5,4,3,2]; 859 860 // Government departments 861 if (vatnumber.substr(0,2) == 'GD') { 862 if (vatnumber.substr(2,3) < 500) 863 return true; 864 else 865 return false; 866 } 867 868 // Health authorities 869 if (vatnumber.substr(0,2) == 'HA') { 870 if (vatnumber.substr(2,3) > 499) 871 return true; 872 else 873 return false; 874 } 875 876 // Standard and Commercial Group numbers 877 var total = 0; 878 879 // A VAT number of all zeros is disallowed 880 if (vatnumber.slice(0) == 0) return false; 881 882 // Check range is OK for modulus 97 calculation 883 var no = Number(vatnumber.slice(0,7)); 884 885 // Extract the next digit and multiply by the counter. 886 for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
887 888 // Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our 889 // VAT number could use either system, so we check it against both. 890 891 // Establish check digits by subtracting 97 from total until negative. 892 var cd = total; 893 while (cd > 0) {cd = cd - 97;} 894 895 // Get the absolute value and compare it with the last two characters of the VAT number. If the 896 // same, then it is a valid traditional check digit. However, even then the number must fit within 897 // certain specified ranges. 898 cd = Math.abs(cd); 899 if (cd == vatnumber.slice (7,9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true; 900 901 // Now try the new method by subtracting 55 from the check digit if we can - else add 42 902 if (cd >= 55) 903 cd = cd - 55; 904 else 905 cd = cd + 42; 906 if (cd == vatnumber.slice (7) && no > 1000000) 907 return true; 908 else 909 return false; 910} 911 912function HRVATCheckDigit (vatnumber) { 913 914 // Validates a Croatian VAT number 915 916 var product = 10; 917 var sum = 0; 918 919 for (var i = 0; i < 10; i++) { 920 921 // Extract the next digit and implement the algorithm 922 sum = (Number(vatnumber.charAt(i)) + product) % 10; 923 if (sum == 0) sum = 10; 924 product = (2 * sum) % 11; 925 } 926 927 // Now check that we have the right check digit 928 if ((product + vatnumber.slice (10)*1) % 10== 1) 929 return true; 930 else 931 return false; 932} 933 934function HUVATCheckDigit (vatnumber) { 935 936 // Validatesf a Hungarian VAT number. 937 938 var total = 0; 939 var multipliers = [9,7,3,1,9,7,3]; 940 941 // Extract the next digit and multiply by the counter. 942 for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
943 944 // Establish check digit. 945 total = 10 - total % 10; 946 if (total == 10) total = 0; 947 948 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 949 if (total == vatnumber.slice (7)) 950 return true; 951 else 952 return false; 953} 954 955function IEVATCheckDigit (vatnumber) { 956 957 // Validates an Irish VAT number. 958 959 var total = 0; 960 var multipliers = [8,7,6,5,4,3,2]; 961 962 // If the code is type 1 format, we need to convert it to the new before performing the validation. 963 if (/^\d[A-Z\*\+]/.test(vatnumber)) vatnumber = "0" + vatnumber.substring(2,7) + vatnumber.substring(0,1) + vatnumber.substring(7,8); 964 965 // Extract the next digit and multiply by the counter. 966 for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 967 968 // If the number is type 3 then we need to include the trailing A or H in the calculation 969 if (/^\d{7}[A-Z][AH]$/.test(vatnumber)) { 970 971 // Add in a multiplier for the character A (1*9=9) or H (8*9=72) 972 if (vatnumber.charAt(8) == 'H') 973 total += 72; 974 else 975 total += 9; 976 } 977 978 // Establish check digit using modulus 23, and translate to char. equivalent. 979 total = total % 23; 980 if (total == 0) 981 total = "W"; 982 else 983 total = String.fromCharCode(total+64); 984 985 // Compare it with the eighth character of the VAT number. If it's the same, then it's valid. 986 if (total == vatnumber.slice (7,8)) 987 return true; 988 else 989 return false; 990} 991 992function ILVATCheckDigit (vatnumber) { 993 994 // Validates an Israeli VAT number. 995 996 var total = 0; 997 var multipliers = [1,2,1,2,1,2,1,2]; 998 var temp; 999 1000 // Pad left with zeros if not 9 characters 1001 vatnumber = ("000000000" + vatnumber).slice(-9); 1002 1003 // Extract the next digit and multiply by the appropriate 1004 for (var i = 0; i < 8; i++) { 1005 temp = Number(vatnumber.charAt(i)) * multipliers[i];
1006 if (temp > 9) 1007 total += Math.floor(temp/10) + temp%10; 1008 else 1009 total += temp; 1010 } 1011 1012 // Establish check digit. 1013 total = 10 - total % 10; 1014 if (total > 9) total = 0; 1015 1016 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1017 if (total == vatnumber.slice (8)) 1018 return true; 1019 else 1020 return false; 1021} 1022 1023function ITVATCheckDigit (vatnumber) { 1024 1025 // Validates an Italian VAT number. 1026 1027 var total = 0; 1028 var multipliers = [1,2,1,2,1,2,1,2,1,2]; 1029 var temp; 1030 1031 // The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888 1032 if (Number(vatnumber.slice(0,7))==0) return false; 1033 temp=Number(vatnumber.slice(7,10)); 1034 if ((temp<1) || (temp>201) && temp != 999 && temp != 888) return false; 1035 1036 // Extract the next digit and multiply by the appropriate 1037 for (var i = 0; i < 10; i++) { 1038 temp = Number(vatnumber.charAt(i)) * multipliers[i]; 1039 if (temp > 9) 1040 total += Math.floor(temp/10) + temp%10; 1041 else 1042 total += temp; 1043 } 1044 1045 // Establish check digit. 1046 total = 10 - total % 10; 1047 if (total > 9) total = 0; 1048 1049 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1050 if (total == vatnumber.slice (10)) 1051 return true; 1052 else 1053 return false; 1054} 1055 1056function LTVATCheckDigit (vatnumber) { 1057 1058 // Validates a Lithuanian VAT number. 1059 1060 var total, multipliers, i; 1061 1062 // 9 character VAT numbers are for legal persons 1063 if (vatnumber.length == 9) { 1064 1065 // 8th character must be one 1066 if (!(/^\d{7}1/).test(vatnumber)) return false; 1067 1068 // Extract the next digit and multiply by the counter+1. 1069 total = 0; 1070 for (i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * (i+1); 1071 1072 // Can have a double check digit calculation! 1073 if (total % 11 == 10) { 1074 multipliers = [3,4,5,6,7,8,9,1]; 1075 total = 0; 1076 for (i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1077 } 1078 1079 // Establish check digit. 1080 total = total % 11; 1081 if (total == 10) total = 0; 1082 1083 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1084 if (total == vatnumber.slice (8)) 1085 return true; 1086 else 1087 return false; 1088 } 1089 1090 // 12 character VAT numbers are for temporarily registered taxpayers 1091 else { 1092 1093 // 11th character must be one 1094 if (!(/^\d{10}1/).test(vatnumber)) return false; 1095 1096 // Extract the next digit and multiply by the counter+1. 1097 total = 0; 1098 multipliers = [1,2,3,4,5,6,7,8,9,1,2]; 1099 for (i = 0; i < 11; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 1100 1101 // Can have a double check digit calculation! 1102 if (total % 11 == 10) { 1103 multipliers = [3,4,5,6,7,8,9,1,2,3,4]; 1104 total = 0; 1105 for (i = 0; i < 11; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 1106 } 1107 1108 // Establish check digit. 1109 total = total % 11; 1110 if (total == 10) total = 0; 1111 1112 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1113 if (total == vatnumber.slice (11)) 1114 return true; 1115 else 1116 return false; 1117 } 1118} 1119 1120function LUVATCheckDigit (vatnumber) { 1121 1122 // Validates a Luxembourg VAT number. 1123 1124 if (vatnumber.slice (0,6) % 89 == vatnumber.slice (6)) 1125 return true; 1126 else 1127 return false; 1128} 1129 1130function LVVATCheckDigit (vatnumber) { 1131 1132 // CValidates a Latvian VAT number. 1133 1134 // Differentiate between legal entities and natural bodies. For the latter we simply check that 1135 // the first six digits correspond to valid DDMMYY dates. 1136 if ((/^[0-3]/).test(vatnumber)) { 1137 if ((/^[0-3][0-9][0-1][0-9]/).test(vatnumber) ) 1138 return true; 1139 else 1140 return false; 1141 } 1142 1143 else { 1144 1145 var total = 0; 1146 var multipliers = [9,1,4,8,3,10,2,5,7,6]; 1147 1148 // Extract the next digit and multiply by the counter. 1149 for (var i = 0; i < 10; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1150 1151 // Establish check digits by getting modulus 11. 1152 if (total%11 == 4 && vatnumber[0] ==9) total = total - 45; 1153 if (total%11 == 4) 1154 total = 4 - total%11; 1155 else if (total%11 > 4) 1156 total = 14 - total%11; 1157 else if (total%11 < 4) 1158 total = 3 - total%11; 1159 1160 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1161 if (total == vatnumber.slice (10)) 1162 return true; 1163 else 1164 return false; 1165 } 1166} 1167 1168function MTVATCheckDigit (vatnumber) { 1169 1170 // Validates a Maltese VAT number. 1171 1172 var total = 0; 1173 var multipliers = [3,4,6,7,8,9]; 1174 1175 // Extract the next digit and multiply by the counter. 1176 for (var i = 0; i < 6; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 1177 1178 // Establish check digits by getting modulus 37. 1179 total = 37 - total % 37; 1180 1181 // Compare it with the last two characters of the VAT number. If it's the same, then it's valid. 1182 if (total == vatnumber.slice (6)) 1183 return true; 1184 else 1185 return false; 1186} 1187 1188function NLVATCheckDigit (vatnumber) { 1189 1190 // Validates a Dutch VAT number. 1191 1192 // Function to turn a Dutch VAT number in its entirety to a numeric equivalent 1193 function convert_string_tonumeric (vatstring) { 1194 1195 // Add 'NL' back to front of string 1196 var vat = 'NL' + vatstring; 1197 1198 // Each character in the string is looked at one at a time 1199 var nextchar = ''; 1200 1201 // The result of the conversion goes here 1202 var result = ''; 1203 1204 for (var i = 0; i < vat.length; i++) { 1205 1206 // Pick up the next character from the vat string as Unicode 1207 nextchar = vat.charCodeAt(i); 1208 1209 // If it is a '*' convert to numeric 36 1210 if (nextchar == 42) 1211 nextchar = 37; 1212 1213 // If it is a '+' convert to numeric 37 1214 else if (nextchar == 43) 1215 nextchar = 36; 1216 1217 // Convert 0 to 9 to 0 to 9 characters 1218 else if (nextchar > 47 && nextchar < 58) 1219 nextchar = nextchar - 48; 1220 1221 // Convert A-Z to 10 to 35 1222 else if (nextchar > 64 && nextchar < 91) 1223 nextchar = nextchar - 55; 1224 1225 // Add to convert test string 1226 result = result + nextchar; 1227 } 1228 return result; 1229 } 1230 1231 // Function to calculate the modulus of a long number 1232 function modulo (divident, divisor) { 1233 1234 var partLength = 7; 1235 1236 while (divident.length > partLength) { 1237 var part = divident.substring(0, partLength); 1238 divident = (part % divisor) + divident.substring(partLength); 1239 } 1240 1241 return divident % divisor; 1242 } 1243 1244 function standardNo () { 1245 1246 // Checks the check digits of a Dutch VAT number. 1247 1248 var total = 0; 1249 var multipliers = [9,8,7,6,5,4,3,2]; 1250 1251 // Extract the next digit and multiply by the counter. 1252 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1253 1254 // Establish check digits by getting modulus 11. 1255 total = total % 11; 1256 if (total > 9) total = 0; 1257 1258 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1259 if (total == vatnumber.slice (8,9)) 1260 return true; 1261 else 1262 return false; 1263 } 1264 1265 function soleproprietorNo (vatnumber) { 1266 1267 // Checks the check digit of a sole proprietor Dutch VAT number 1268 var numericvat = convert_string_tonumeric (vatnumber); 1269 if (modulo (numericvat, 97) == 1) 1270 return true; 1271 else 1272 return false; 1273 } 1274 1275 // First check whether the VAT number is a valid standard one 1276 if (standardNo (vatnumber)) 1277 return true; 1278 1279 // If not, check whether it is a valid sole proprietor vat number 1280 else if (soleproprietorNo (vatnumber)) 1281 return true; 1282 1283 // Neither - it must be invalid 1284 else return false; 1285} 1286 1287function NOVATCheckDigit (vatnumber) { 1288 1289 // Validates a Norwegian VAT number. 1290 // See http://www.brreg.no/english/coordination/number.html 1291 1292 var total = 0; 1293 var multipliers = [3,2,7,6,5,4,3,2]; 1294 1295 // Extract the next digit and multiply by the counter. 1296 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1297 1298 // Establish check digits by getting modulus 11. Check digits > 9 are invalid 1299 total = 11 - total % 11; 1300 if (total == 11) {total = 0;} 1301 if (total < 10) { 1302 1303 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1304 if (total == vatnumber.slice (8)) 1305 return true; 1306 else 1307 return false; 1308 } 1309} 1310 1311function PLVATCheckDigit (vatnumber) { 1312 1313 // Validates a Polish VAT number. 1314 1315 var total = 0; 1316 var multipliers = [6,5,7,2,3,4,5,6,7]; 1317 1318 // Extract the next digit and multiply by the counter. 1319 for (var i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 1320 1321 // Establish check digits subtracting modulus 11 from 11. 1322 total = total % 11; 1323 if (total > 9) total = 0; 1324 1325 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1326 if (total == vatnumber.slice (9)) 1327 return true; 1328 else 1329 return false; 1330} 1331 1332function PTVATCheckDigit (vatnumber) { 1333 1334 // Validates a Portuguese VAT number. 1335 1336 var total = 0; 1337 var multipliers = [9,8,7,6,5,4,3,2]; 1338 1339 // Extract the next digit and multiply by the counter. 1340 for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1341 1342 // Establish check digits subtracting modulus 11 from 11. 1343 total = 11 - total % 11; 1344 if (total > 9) total = 0; 1345 1346 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1347 if (total == vatnumber.slice (8)) 1348 return true; 1349 else 1350 return false; 1351} 1352 1353function ROVATCheckDigit (vatnumber) { 1354 1355 // Validates a Romanian VAT number. 1356 1357 var multipliers = [7,5,3,2,1,7,5,3,2]; 1358 1359 // Pad left with zeros if not 10 characters 1360 vatnumber = ("000000000" + vatnumber).slice(-10); 1361 1362 // Extract the next digit and multiply by the counter. 1363 var total = 0; 1364 for (var i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i]; 1365 1366 // Establish check digits by getting modulus 11. 1367 total = (10 * total) % 11; 1368 if (total == 10) total = 0; 1369 1370 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1371 if (total == vatnumber.slice (9)) 1372 return true; 1373 else 1374 return false; 1375} 1376 1377function RSVATCheckDigit (vatnumber) { 1378 1379 // Validates a Serbian VAT number 1380 1381 var product = 10; 1382 var sum = 0; 1383 1384 for (var i = 0; i < 8; i++) { 1385 1386 // Extract the next digit and implement the algorithm 1387 sum = (Number(vatnumber.charAt(i)) + product) % 10; 1388 if (sum == 0) sum = 10; 1389 product = (2 * sum) % 11; 1390 } 1391 1392 // Now check that we have the right check digit 1393 if ((product + vatnumber.slice (8)*1) % 10== 1) 1394 return true; 1395 else 1396 return false; 1397} 1398 1399function RUVATCheckDigit (vatnumber) { 1400 1401 // Validates a Russian INN number 1402 // See http://russianpartner.biz/test_inn.html for algorithm 1403 1404 var i; 1405 1406 // 10 digit INN numbers 1407 if (vatnumber.length == 10) { 1408 var total = 0; 1409 var multipliers = [2,4,10,3,5,9,4,6,8,0]; 1410 for (i = 0; i < 10; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1411 total = total % 11; 1412 if (total > 9) total = total % 10; 1413 1414 // Compare it with the last character of the VAT number. If it is the same, then it's valid 1415 if (total == vatnumber.slice (9)) 1416 return true; 1417 else 1418 return false; 1419 1420 // 12 digit INN numbers 1421 } 1422 else if (vatnumber.length == 12){ 1423 var total1 = 0; 1424 var multipliers1 = [7,2,4,10,3,5,9,4,6,8,0]; 1425 var total2 = 0; 1426 var multipliers2 = [3,7,2,4,10,3,5,9,4,6,8,0]; 1427 1428 for (i = 0; i < 11; i++) total1 += Number(vatnumber.charAt(i)) * multipliers1[i]; 1429 total1 = total1 % 11; 1430 if (total1 > 9) total1 = total1 % 10; 1431 1432 for (i = 0; i < 11; i++) total2 += Number(vatnumber.charAt(i)) * multipliers2[i]; 1433 total2 = total2 % 11; 1434 if (total2 > 9) total2 = total2 % 10; 1435 1436 // Compare the first check with the 11th character and the second check with the 12th and last 1437 // character of the VAT number. If they're both the same, then it's valid 1438 if ((total1 == vatnumber.slice (10,11)) && (total2 == vatnumber.slice (11,12))) 1439 return true; 1440 else 1441 return false; 1442 } 1443} 1444 1445function SEVATCheckDigit (vatnumber) { 1446 1447 // Validates a Swedish VAT number 1448 1449 // Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10 1450 var R = 0; 1451 var digit; 1452 for (var i = 0; i < 9; i=i+2) { 1453 digit = Number(vatnumber.charAt(i)); 1454 R += Math.floor(digit / 5) + ((digit * 2) % 10); 1455 } 1456 1457 // Calculate S where S = C2 + C4 + C6 + C8 1458 var S = 0; 1459 for (i = 1; i < 9; i=i+2) S += Number(vatnumber.charAt(i)); 1460 1461 // Calculate the Check Digit 1462 var cd = (10 - (R + S) % 10) % 10; 1463 1464 // Compare it with the last character of the VAT number. If it's the same, then it's valid. 1465 if (cd == vatnumber.slice (9,10)) 1466 return true; 1467 else 1468 return false; 1469} 1470 1471function SIVATCheckDigit (vatnumber) { 1472 1473 // Validates a Slovenian VAT number. 1474 1475 var total = 0; 1476 var multipliers = [8,7,6,5,4,3,2]; 1477 var i; 1478 1479 // Extract the next digit and multiply by the counter. 1480 for (i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1481 1482 // Establish check digits using modulus 11 1483 total = 11 - total % 11; 1484 if (total == 10) total = 0; 1485 1486 // Compare the number with the last character of the VAT number. If it is the 1487 // same, then it's a valid check digit. 1488 if (total != 11 && total == vatnumber.slice (7)) 1489 return true; 1490 else 1491 return false; 1492} 1493 1494function SKVATCheckDigit (vatnumber) { 1495 1496 // Validates a Slovakian VAT number. 1497 1498 // Check that the modulus of the whole VAT number is 0 - else error 1499 if (Number(vatnumber % 11) == 0) 1500 return true; 1501 else 1502 return false; 1503}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.