PageSourceSearch

https://www.meritsummit.com/public/assets/scripts/libs/vat-validation/1.29/main.js?ver=4.0.2.37

js meritsummit.com collected 2026-10-04 08:37:49 UTC 41,576 bytes, 1,276 lines download raw bytes

1/*==================================================================================================
2
3Application:   Utility Function
4Author:        John Gardner
5Website:       http://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              
158Parameters:    toCheck - VAT number be checked. 
159
160This function checks the value of the parameter for a valid European VAT number. 
161
162If the number is found to be invalid format, the function returns a value of false. Otherwise it 
163returns the VAT number re-formatted.
164  
165Example call:
166  
167  if (checkVATNumber (myVATNumber)) 
168      alert ("VAT number has a valid format")
169  else 
170      alert ("VAT number has invalid format");
171                    
172---------------------------------------------------------------------------------------------------*/
173
174function checkVATNumber (toCheck) {
175 
176  // Array holds the regular expressions for the valid VAT number
177  var vatexp = new Array ();
178  
179  // To change the default country (e.g. from the UK to Germany - DE):
180  //    1.  Change the country code in the defCCode variable below to "DE".
181  //    2.  Remove the question mark from the regular expressions associated with the UK VAT number: 
182  //        i.e. "(GB)?" -> "(GB)"
183  //    3.  Add a question mark into the regular expression associated with Germany's number 
184  //        following the country code: i.e. "(DE)" -> "(DE)?"
185  
186  var defCCode = "GB";
187  
188  // Note - VAT codes without the "**" in the comment do not have check digit checking.
189
190  vatexp.push (/^(AT)U(\d{8})$/);                           //** Austria
191  vatexp.push (/^(BE)(0?\d{9})$/);                          //** Belgium 
192  vatexp.push (/^(BG)(\d{9,10})$/);                         //** Bulgaria 
193  vatexp.push (/^(CHE)(\d{9})(MWST|TVA|IVA)?$/);            //** Switzerland
194  vatexp.push (/^(CY)([0-59]\d{7}[A-Z])$/);                 //** Cyprus
195  vatexp.push (/^(CZ)(\d{8,10})(\d{3})?$/);                 //** Czech Republic
196  vatexp.push (/^(DE)([1-9]\d{8})$/);                       //** Germany 
197  vatexp.push (/^(DK)(\d{8})$/);                            //** Denmark 
198  vatexp.push (/^(EE)(10\d{7})$/);                          //** Estonia 
199  vatexp.push (/^(EL)(\d{9})$/);                            //** Greece 
200  vatexp.push (/^(ES)([A-Z]\d{8})$/);                       //** Spain (National juridical entities)
201  vatexp.push (/^(ES)([A-HN-SW]\d{7}[A-J])$/);              //** Spain (Other juridical entities)
202  vatexp.push (/^(ES)([0-9YZ]\d{7}[A-Z])$/);
202                //** Spain (Personal entities type 1)
203  vatexp.push (/^(ES)([KLMX]\d{7}[A-Z])$/);                 //** Spain (Personal entities type 2)
204  vatexp.push (/^(EU)(\d{9})$/);                            //** EU-type 
205  vatexp.push (/^(FI)(\d{8})$/);                            //** Finland 
206  vatexp.push (/^(FR)(\d{11})$/);                           //** France (1)
207  vatexp.push (/^(FR)([A-HJ-NP-Z]\d{10})$/);                // France (2)
208  vatexp.push (/^(FR)(\d[A-HJ-NP-Z]\d{9})$/);               // France (3)
209  vatexp.push (/^(FR)([A-HJ-NP-Z]{2}\d{9})$/);              // France (4)
210  vatexp.push (/^(GB)?(\d{9})$/);                           //** UK (Standard)
211  vatexp.push (/^(GB)?(\d{12})$/);                          //** UK (Branches)
212  vatexp.push (/^(GB)?(GD\d{3})$/);                         //** UK (Government)
213  vatexp.push (/^(GB)?(HA\d{3})$/);                         //** UK (Health authority)
214  vatexp.push (/^(HR)(\d{11})$/);                           //** Croatia 
215  vatexp.push (/^(HU)(\d{8})$/);                            //** Hungary 
216  vatexp.push (/^(IE)(\d{7}[A-W])$/);                       //** Ireland (1)
217  vatexp.push (/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/);        //** Ireland (2)
218  vatexp.push (/^(IE)(\d{7}[A-W][AH])$/);                   //** Ireland (3)
219  vatexp.push (/^(IT)(\d{11})$/);                           //** Italy 
220  vatexp.push (/^(LV)(\d{11})$/);                           //** Latvia 
221  vatexp.push (/^(LT)(\d{9}|\d{12})$/);                     //** Lithunia
222  vatexp.push (/^(LU)(\d{8})$/);                            //** Luxembourg 
223  vatexp.push (/^(MT)([1-9]\d{7})$/);                       //** Malta
224  vatexp.push (/^(NL)(\d{9})B\d{2}$/);                      //** Netherlands
225  vatexp.push (/^(NO)(\d{9})$/);                            //** Norway (not EU)
226  vatexp.push (/^(PL)(\d{10})$/);                           //** Poland
227  vatexp.push (/^(PT)(\d{9})$/);                            //** Portugal
228  vatexp.push (/^(RO)([1-9]\d{1,9})$/);                     //** Romania
229  vatexp.push (/^(RU)(\d{10}|\d{12})$/);                    //** Russia
230  vatexp.push (/^(RS)(\d{9})$/);                            //** Serbia
231  vatexp.push (/^(SI)([1-9]\d{7})$/);                       //** Slovenia
232  vatexp.push (/^(SK)([1-9]\d[2346-9]\d{7})$/);             //** Slovakia Republic
233  vatexp.push (/^(SE)(\d{10}01)$/);                         //** Sweden
234
235  // Load up the string to check
236  var VATNumber = toCheck.toUpperCase();
237  
238  // Remove spaces etc. from the VAT number to help validation
239  VATNumber = VATNumber.replace (/(\s|-|\.)+/g, '');
240
241  // Assume we're not going to find a valid VAT number
242  var valid = false;                         
243  
244  // Check the string against the regular expressions for all types of VAT numbers
245  for (i=0; i<vatexp.length; i++) {
246  
247    // Have we recognised the VAT number?
248    if (vatexp[i].test(VATNumber)) {
249      
250      // Yes - we have
251      var cCode = RegExp.$1;                             // Isolate country code
252      var cNumber = RegExp.$2;                           // Isolate the number
253      if (cCode.length == 0) cCode = defCCode;           // Set up default country code
254      
255      // Call the appropriate country VAT validation routine depending on the country code
256      if (eval(cCode+"VATCheckDigit ('"+cNumber+"')")) valid = VATNumber;
257      
258      // Having processed the number, we break from the loop
259      break;
260    }
261  }
262  
263  // Return with either an error or the reformatted VAT number
264  return valid;
265}
266
267function ATVATCheckDigit (vatnumber) {
268
269  // Checks the check digits of an Austrian VAT number.
270  
271  var total = 0;
272  var multipliers = [1,2,1,2,1,2,1];
273  var temp = 0;
274  
275  // Extract the next digit and multiply by the appropriate multiplier.  
276  for (var i = 0; i < 7; i++) {
277    temp = Number(vatnumber.charAt(i)) * multipliers[i];
278    if (temp > 9)
279      total += Math.floor(temp/10) + temp%10
280    else
281      total += temp;
282  }  
283  
284  // Establish check digit.
285  total = 10 - (total+4) % 10; 
286  if (total == 10) total = 0;
287  
288  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
289  if (total == vatnumber.slice (7,8)) 
290    return true
291  else 
292    return false;
293}
294
295function BEVATCheckDigit (vatnumber) {
296
297  // Checks the check digits of a Belgium VAT number.
298  
299  // Nine digit numbers have a 0 inserted at the front.
300  if (vatnumber.length == 9) vatnumber = "0" + vatnumber;
301  
302  if (vatnumber.slice(1,2) == 0) return false;
303  
304  // Modulus 97 check on last nine digits
305  if (97 - vatnumber.slice (0,8) % 97 == vatnumber.slice (8,10)) 
306    return true
307  else 
308    return false;
309}
310
311function BGVATCheckDigit (vatnumber) {
312
313  // Checks the check digits of a Bulgarian VAT number.
314
315  if (vatnumber.length == 9) {
316  
317    // Check the check digit of 9 digit Bulgarian VAT numbers.
318    var total = 0;
319    
320    // First try to calculate the check digit using the first multipliers  
321    var temp = 0;
322    for (var i = 0; i < 8; i++) temp += Number(vatnumber.charAt(i)) * (i+1);
323    
324    // See if we have a check digit yet
325    total = temp % 11; 
326    if (total != 10) {
327      if (total == vatnumber.slice (8)) 
328        return true
329      else 
330        return false;
331    }
332  
333    // We got a modulus of 10 before so we have to keep going. Calculate the new check digit using  
334    // the different multipliers  
335    var temp = 0;
336    for (var i = 0; i < 8; i++) temp += Number(vatnumber.charAt(i)) * (i+3);
337    
338    // See if we have a check digit yet. If we still have a modulus of 10, set it to 0.
339    total = temp % 11; 
340    if (total == 10) total = 0;
341    if (total == vatnumber.slice (8)) 
342      return true
343    else 
344      return false;
345  }
346  
347  // 10 digit VAT code - see if it relates to a standard physical person
348  if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vatnumber)) {
349  
350    // Check month
351    var month = Number(vatnumber.slice(2,4));
352    if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
353    
354      // Extract the next digit and multiply by the counter.
355      var multipliers = [2,4,8,5,10,9,7,3,6];    
356      var total = 0;
357      for (var i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
358      
359      // Establish check digit.
360      total = total % 11;
361      if (total == 10) total = 0;  
362      
363      // Check to see if the check digit given is correct, If not, try next type of person
364      if (total == vatnumber.substr (9,1)) return true;
365    }
366  }
367  
368  // It doesn't relate to a standard physical person - see if it relates to a foreigner.
369  
370  // Extract the next digit and multiply by the counter.
371  var multipliers = [21,19,17,13,11,9,7,3,1];    
372  var total = 0;
373  for (var i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
374  
375  // Check to see if the check digit given is correct, If not, try next type of person
376  if (total % 10 == vatnumber.substr (9,1)) return true;
377  
378  // Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
379  
380  // Extract the next digit and multiply by the counter.
381  var multipliers = [4,3,2,7,6,5,4,3,2];    
382  var total = 0;
383  for (var i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
384  
385  // Establish check digit.
386  total = 11 - total % 11;
387  if (total == 10) return false;  
388  if (total == 11) total = 0;  
389  
390  // Check to see if the check digit given is correct, If not, we have an error with the VAT number
391  if (total == vatnumber.substr (9,1)) 
392    return true;
393  else
394    return false;
395}
396
397function CHEVATCheckDigit (vatnumber) {
398
399  // Checks the check digits of a Swiss VAT number.
400  
401  // Extract the next digit and multiply by the counter.
402  var multipliers = [5,4,3,2,7,6,5,4];    
403  var total = 0;
404  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
405  
406  // Establish check digit.
407  total = 11 - total % 11;
408  if (total == 10) return false;  
409  if (total == 11) total = 0;  
410  
411  // Check to see if the check digit given is correct, If not, we have an error with the VAT number
412  if (total == vatnumber.substr (8,1)) 
413    return true;
414  else
415    return false;
416}
417
418function CYVATCheckDigit (vatnumber) {
419
420  // Checks the check digits of a Cypriot VAT number.
421  
422  // Not allowed to start with '12'
423  if (Number(vatnumber.slice(0,2) == 12)) return false;
424  
425  // Extract the next digit and multiply by the counter.
426  var total = 0;
427  for (var i = 0; i < 8; i++) {
428    var temp = Number(vatnumber.charAt(i));
429    if (i % 2 == 0) {
430      switch (temp) {
431        case 0: temp = 1; break;
432        case 1: temp = 0; break;
433        case 2: temp = 5; break;
434        case 3: temp = 7; break;
435        case 4: temp = 9; break;
436        default: temp = temp*2 + 3;
437      }
438    }
439    total += temp;
440  }
441  
442  // Establish check digit using modulus 26, and translate to char. equivalent.
443  total = total % 26;
444  total = String.fromCharCode(total+65);
445  
446  // Check to see if the check digit given is correct
447  if (total == vatnumber.substr (8,1)) 
448    return true 
449  else 
450    return false;
451}
452
453function CZVATCheckDigit (vatnumber) {
454
455  // Checks the check digits of a Czech Republic VAT number.
456  
457  var total = 0;
458  var multipliers = [8,7,6,5,4,3,2];
459  
460  var czexp = new Array ();
461  czexp[0] = (/^\d{8}$/);                                       //  8 digit legal entities
462  // Note - my specification says that that the following should have a range of 0-3 in the fourth
463  // digit, but the valid number CZ395601439 did not confrm, so a range of 0-9 has been allowed.
464  czexp[1] = (/^[0-5][0-9][0|1|5|6][0-9][0-3][0-9]\d{3}$/);     //  9 digit individuals
465  czexp[2] = (/^6\d{8}$/);                                      //  9 digit individuals (Special cases)
466  czexp[3] = (/^\d{2}[0-3|5-8][0-9][0-3][0-9]\d{4}$/);          // 10 digit individuals
467  var i = 0;
468  
469  // Legal entities
470  if (czexp[0].test(vatnumber)) {    
471    
472    // Extract the next digit and multiply by the counter.
473    for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
474    
475    // Establish check digit.
476    total = 11 - total % 11;
477    if (total == 10) total = 0; 
478    if (total == 11) total = 1; 
479    
480    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
481    if (total == vatnumber.slice (7,8)) 
482      return true
483    else 
484      return false;
485  }  
486  
487  // Individuals type 1 (Standard) - 9 digits without check digit
488  else if (czexp[1].test(vatnumber)) {
489    if (temp = Number(vatnumber.slice(0,2)) > 62) return false;
490    return true;
491  }
492  
493  // Individuals type 2 (Special Cases) - 9 digits including check digit
494  else if (czexp[2].test(vatnumber)) {  
495    
496    // Extract the next digit and multiply by the counter.
497    for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i+1)) * multipliers[i];
498    
499    // Establish check digit pointer into lookup table
500    if (total % 11 == 0)
501      var a = total + 11
502    else
503      var a = Math.ceil (total/11) * 11;
504    var pointer = a - total;
505    
506    // Convert calculated check digit according to a lookup table;
507    var lookup  = [8,7,6,5,4,3,2,1,0,9,8];
508    if (lookup[pointer-1] == vatnumber.slice (8,9)) 
509      return true
510    else 
511      return false;
512  }
513  
514  // Individuals type 3 - 10 digits
515  else if (czexp[3].test(vatnumber)) {
516    var 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));
517    if (temp % 11 == 0 && Number(vatnumber) % 11 == 0)
518      return true
519    else
520      return false;
521  }
522  
523  // else error
524  return false;
525}
526
527function DEVATCheckDigit (vatnumber) {
528
529  // Checks the check digits of a German VAT number.
530  
531  var product = 10;
532  var sum = 0;     
533  var checkdigit = 0;                      
534  for (var i = 0; i < 8; i++) {
535    
536    // Extract the next digit and implement peculiar algorithm!.
537    sum = (Number(vatnumber.charAt(i)) + product) % 10;
538    if (sum == 0) {sum = 10};
539    product = (2 * sum) % 11;
540  }
541  
542  // Establish check digit.  
543  if (11 - product == 10) {checkdigit = 0} else {checkdigit = 11 - product};
544  
545  // Compare it with the last two characters of the VAT number. If the same, then it is a valid 
546  // check digit.
547  if (checkdigit == vatnumber.slice (8,9))
548    return true
549  else 
550    return false;
551}
552
553function DKVATCheckDigit (vatnumber) {
554
555  // Checks the check digits of a Danish VAT number.
556  
557  var total = 0;
558  var multipliers = [2,7,6,5,4,3,2,1];
559  
560  // Extract the next digit and multiply by the counter.
561  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
562  
563  // Establish check digit.
564  total = total % 11;
565  
566  // The remainder should be 0 for it to be valid..
567  if (total == 0) 
568    return true
569  else 
570    return false;
571}
572
573function EEVATCheckDigit (vatnumber) {
574
575  // Checks the check digits of an Estonian VAT number.
576  
577  var total = 0;
578  var multipliers = [3,7,1,3,7,1,3,7];
579  
580  // Extract the next digit and multiply by the counter.
581  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
582  
583  // Establish check digits using modulus 10.
584  total = 10 - total % 10;
585  if (total == 10) total = 0;
586  
587  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
588  if (total == vatnumber.slice (8,9))
589    return true
590  else 
591    return false;
592}
593
594function ELVATCheckDigit (vatnumber) {
595
596  // Checks the check digits of a Greek VAT number.
597  
598  var total = 0;
599  var multipliers = [256,128,64,32,16,8,4,2];
600  
601  //eight character numbers should be prefixed with an 0.
602  if (vatnumber.length == 8) {vatnumber = "0" + vatnumber};
603  
604  // Extract the next digit and multiply by the counter.
605  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
606  
607  // Establish check digit.
608  total = total % 11;
609  if (total > 9) {total = 0;};  
610  
611  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
612  if (total == vatnumber.slice (8,9)) 
613    return true
614  else 
615    return false;
616}
617
618function ESVATCheckDigit (vatnumber) {
619
620  // Checks the check digits of a Spanish VAT number.
621  
622  var total = 0; 
623  var temp = 0;
624  var multipliers = [2,1,2,1,2,1,2];
625  var esexp = new Array ();
626  esexp[0] = (/^[A-H|J|U|V]\d{8}$/);
627  esexp[1] = (/^[A-H|N-S|W]\d{7}[A-J]$/);
628  esexp[2] = (/^[0-9|Y|Z]\d{7}[A-Z]$/);
629  esexp[3] = (/^[K|L|M|X]\d{7}[A-Z]$/);
630  var i = 0;
631  
632  // National juridical entities
633  if (esexp[0].test(vatnumber)) {
634  
635    // Extract the next digit and multiply by the counter.
636    for (i = 0; i < 7; i++) {
637      temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
638      if (temp > 9) 
639        total += Math.floor(temp/10) + temp%10 
640      else 
641        total += temp;
642    }   
643    // Now calculate the check digit itself. 
644    total = 10 - total % 10;
645    if (total == 10) {total = 0;}
646    
647    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
648    if (total == vatnumber.slice (8,9)) 
649      return true
650    else 
651      return false;
652  }
653  
654  // Juridical entities other than national ones
655  else if (esexp[1].test(vatnumber)) {
656  
657    // Extract the next digit and multiply by the counter.
658    for (i = 0; i < 7; i++) {
659      temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
660      if (temp > 9) 
661        total += Math.floor(temp/10) + temp%10 
662      else 
663        total += temp;
664    }    
665    
666    // Now calculate the check digit itself.
667    total = 10 - total % 10;
668    total = String.fromCharCode(total+64);
669    
670    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
671    if (total == vatnumber.slice (8,9)) 
672      return true
673    else 
674      return false;
675  }
676	
677  // Personal number (NIF) (starting with numeric of Y or Z)
678  else if (esexp[2].test(vatnumber)) {
679    var tempnumber = vatnumber;
680    if (tempnumber.substring(0,1) == 'Y') tempnumber = tempnumber.replace (/Y/, "1");
681    if (tempnumber.substring(0,1) == 'Z') tempnumber = tempnumber.replace (/Z/, "2");
682  	return tempnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(tempnumber.substring(0,8)) % 23);
683  }
684	
685  // Personal number (NIF) (starting with K, L, M, or X)
686  else if (esexp[3].test(vatnumber)) {
687  	return vatnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(vatnumber.substring(1,8)) % 23);
688  }
689	
690  else return false;
691}
692
693function EUVATCheckDigit (vatnumber) {
694
695  // We know little about EU numbers apart from the fact that the first 3 digits represent the 
696  // country, and that there are nine digits in total.
697  return true;
698}
699
700function FIVATCheckDigit (vatnumber) {
701
702  // Checks the check digits of a Finnish VAT number.
703  
704  var total = 0; 
705  var multipliers = [7,9,10,5,8,4,2];
706  
707  // Extract the next digit and multiply by the counter.
708  for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
709  
710  // Establish check digit.
711  total = 11 - total % 11;
712  if (total > 9) {total = 0;};  
713  
714  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
715  if (total == vatnumber.slice (7,8)) 
716    return true
717  else 
718    return false;
719}
720
721function FRVATCheckDigit (vatnumber) {
722
723  // Checks the check digits of a French VAT number.
724  
725  if (!(/^\d{11}$/).test(vatnumber)) return true;
726  
727  // Extract the last nine digits as an integer.
728  var total = vatnumber.substring(2); 
729  
730  // Establish check digit.
731  total = (total*100+12) % 97;
732  
733  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
734  if (total == vatnumber.slice (0,2)) 
735    return true
736  else 
737    return false;
738}
739
740function GBVATCheckDigit (vatnumber) {
741
742  // Checks the check digits of a UK VAT number.
743  
744  var multipliers = [8,7,6,5,4,3,2];
745  
746  // Government departments
747  if (vatnumber.substr(0,2) == 'GD') {
748    if (vatnumber.substr(2,3) < 500) 
749      return true 
750    else 
751      return false;
752  }
753  
754  // Health authorities
755  if (vatnumber.substr(0,2) == 'HA') {
756    if (vatnumber.substr(2,3) > 499) 
757      return true 
758    else 
759      return false;
760  }
761  
762  // Standard and commercial numbers
763  var total = 0;
764  
765  // 0 VAT numbers disallowed!
766  if (Number(vatnumber.slice(0)) == 0) return false;
767  
768  // Check range is OK for modulus 97 calculation
769  var no = Number(vatnumber.slice(0,7));
770  
771  // Extract the next digit and multiply by the counter.
772  for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
773
774  // Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our 
775  // VAT number could use either system, so we check it against both.
776
777  // Establish check digits by subtracting 97 from total until negative.
778  var cd = total;
779  while (cd > 0) {cd = cd - 97;}    
780
781  // Get the absolute value and compare it with the last two characters of the VAT number. If the 
782  // same, then it is a valid traditional check digit. However, even then the number must fit within
783  // certain specified ranges.
784  cd = Math.abs(cd);
785  if (cd == vatnumber.slice (7,9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
786  
787  // Now try the new method by subtracting 55 from the check digit if we can - else add 42
788  if (cd >= 55) 
789    cd = cd - 55
790  else
791    cd = cd + 42;
792  if (cd == vatnumber.slice (7,9) && no > 1000000) 
793    return true;
794  else
795    return false; 
796}
797
798function HRVATCheckDigit (vatnumber) {
799
800  // Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
801  
802  var product = 10;
803  var sum = 0;     
804  var checkdigit = 0; 
805  
806  for (var i = 0; i < 10; i++) {
807    
808    // Extract the next digit and implement the algorithm
809    sum = (Number(vatnumber.charAt(i)) + product) % 10;
810    if (sum == 0) {sum = 10};
811    product = (2 * sum) % 11;
812  }
813  
814  // Now check that we have the right check digit
815  if ((product + vatnumber.slice (10,11)*1) % 10== 1)
816    return true
817  else 
818    return false;
819}
820
821function HUVATCheckDigit (vatnumber) {
822
823  // Checks the check digits of a Hungarian VAT number.
824  
825  var total = 0;
826  var multipliers = [9,7,3,1,9,7,3];
827  
828  // Extract the next digit and multiply by the counter.
829  for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
830  
831  // Establish check digit.
832  total = 10 - total % 10; 
833  if (total == 10) total = 0;
834  
835  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
836  if (total == vatnumber.slice (7,8)) 
837    return true
838  else 
839    return false;
840}
841
842function IEVATCheckDigit (vatnumber) {
843
844  // Checks the check digits of an Irish VAT number.
845  
846  var total = 0; 
847  var multipliers = [8,7,6,5,4,3,2];  
848 
849  // If the code is type 1 format, we need to convert it to the new before performing the validation.
850  if (/^\d[A-Z\*\+]/.test(vatnumber)) vatnumber = "0" + vatnumber.substring(2,7) + vatnumber.substring(0,1) + vatnumber.substring(7,8);
851    
852  // Extract the next digit and multiply by the counter.
853  for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
854  
855  // If the number is type 3 then we need to include the trailing A or H in the calculation
856  if (/^\d{7}[A-Z][AH]$/.test(vatnumber)) {
857  
858    // Add in a multiplier for the character A (1*9=9) or H (8*9=72)
859    if (vatnumber.charAt(8) == 'H')
860      total += 72
861    else
862      total += 9;    
863  }
864  
865  // Establish check digit using modulus 23, and translate to char. equivalent.
866  total = total % 23;
867  if (total == 0)
868    total = "W"
869  else
870    total = String.fromCharCode(total+64);
871    
872  // Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
873  if (total == vatnumber.slice (7,8)) 
874    return true
875  else 
876    return false;
877}
878
879function ITVATCheckDigit (vatnumber) {
880
881  // Checks the check digits of an Italian VAT number.
882  
883  var total = 0;
884  var multipliers = [1,2,1,2,1,2,1,2,1,2];
885  var temp;
886    
887  // The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
888  if (Number(vatnumber.slice(0,7))==0) return false;
889  temp=Number(vatnumber.slice(7,10));
890  if ((temp<1) || (temp>201) && temp != 999 && temp != 888) return false;
891  
892  // Extract the next digit and multiply by the appropriate  
893  for (var i = 0; i < 10; i++) {
894    temp = Number(vatnumber.charAt(i)) * multipliers[i];
895    if (temp > 9) 
896      total += Math.floor(temp/10) + temp%10 
897    else 
898      total += temp;
899  }
900  
901  // Establish check digit.
902  total = 10 - total % 10;
903  if (total > 9) {total = 0;};  
904  
905  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
906  if (total == vatnumber.slice (10,11)) 
907    return true
908  else 
909    return false;
910}
911
912function LTVATCheckDigit (vatnumber) {
913
914  // Checks the check digits of a Lithuanian VAT number.
915  
916  // 9 character VAT numbers are for legal persons
917  if (vatnumber.length == 9) {
918  
919    // 8th character must be one
920    if (!(/^\d{7}1/).test(vatnumber)) return false;
921    
922    // Extract the next digit and multiply by the counter+1.
923    var total = 0;
924    for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * (i+1);
925    
926    // Can have a double check digit calculation!
927    if (total % 11 == 10) {
928      var multipliers = [3,4,5,6,7,8,9,1];
929      total = 0;
930      for (i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
931    }
932    
933    // Establish check digit.
934    total = total % 11;
935    if (total == 10) {total = 0;}; 
936    
937    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
938    if (total == vatnumber.slice (8,9)) 
939      return true
940    else 
941      return false;
942  }
943  
944  // 12 character VAT numbers are for temporarily registered taxpayers
945  else {
946  
947    // 11th character must be one
948    if (!(/^\d{10}1/).test(vatnumber)) return false;
949    
950    // Extract the next digit and multiply by the counter+1.
951    var total = 0;
952    var multipliers = [1,2,3,4,5,6,7,8,9,1,2];
953    for (var i = 0; i < 11; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
954    
955    // Can have a double check digit calculation!
956    if (total % 11 == 10) {
957      var multipliers = [3,4,5,6,7,8,9,1,2,3,4];
958      total = 0;
959      for (i = 0; i < 11; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
960    }
961    
962    // Establish check digit.
963    total = total % 11;
964    if (total == 10) {total = 0;}; 
965    
966    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
967    if (total == vatnumber.slice (11,12)) 
968      return true
969    else 
970      return false;
971  }
972}
973
974function LUVATCheckDigit (vatnumber) {
975
976  // Checks the check digits of a Luxembourg VAT number.
977  
978  if (vatnumber.slice (0,6) % 89 == vatnumber.slice (6,8)) 
979    return true
980  else 
981    return false;
982}
983
984function LVVATCheckDigit (vatnumber) {
985
986  // Checks the check digits of a Latvian VAT number.
987  
988  // Differentiate between legal entities and natural bodies. For the latter we simply check that
989  // the first six digits correspond to valid DDMMYY dates.
990  if ((/^[0-3]/).test(vatnumber)) {
991    if ((/^[0-3][0-9][0-1][0-9]/).test(vatnumber) )
992      return true
993    else
994      return false;
995  }
996  
997  else {
998  
999    var total = 0;
1000    var multipliers = [9,1,4,8,3,10,2,5,7,6];
1001    
1002    // Extract the next digit and multiply by the counter.
1003    for (var i = 0; i < 10; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1004    
1005    // Establish check digits by getting modulus 11.
1006    if (total%11 == 4 && vatnumber[0] ==9) total = total - 45;
1007    if (total%11 == 4) 
1008      total = 4 - total%11
1009    else if (total%11 > 4) 
1010      total = 14 - total%11
1011    else if (total%11 < 4) 
1012      total = 3 - total%11;
1013    
1014    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1015    if (total == vatnumber.slice (10,11)) 
1016      return true
1017    else 
1018      return false;
1019  }
1020}
1021
1022function MTVATCheckDigit (vatnumber) {
1023
1024  // Checks the check digits of a Maltese VAT number.
1025  
1026  var total = 0;
1027  var multipliers = [3,4,6,7,8,9];
1028  
1029  // Extract the next digit and multiply by the counter.
1030  for (var i = 0; i < 6; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1031  
1032  // Establish check digits by getting modulus 37.
1033  total = 37 - total % 37;
1034  
1035  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1036  if (total == vatnumber.slice (6,8) * 1) 
1037    return true
1038  else 
1039    return false;
1040}
1041
1042function NLVATCheckDigit (vatnumber) {
1043
1044  // Checks the check digits of a Dutch VAT number.
1045  
1046  var total = 0;
1047  var multipliers = [9,8,7,6,5,4,3,2];
1048  
1049  // Extract the next digit and multiply by the counter.
1050  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1051  
1052  // Establish check digits by getting modulus 11.
1053  total = total % 11;
1054  if (total > 9) {total = 0;};  
1055  
1056  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1057  if (total == vatnumber.slice (8,9)) 
1058    return true
1059  else 
1060    return false;
1061}
1062
1063function NOVATCheckDigit (vatnumber) {
1064
1065  // Checks the check digits of a Norwegian VAT number.
1066  // See http://www.brreg.no/english/coordination/number.html
1067  
1068  var total = 0;
1069  var multipliers = [3,2,7,6,5,4,3,2];
1070  
1071  // Extract the next digit and multiply by the counter.
1072  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1073  
1074  // Establish check digits by getting modulus 11. Check digits > 9 are invalid
1075  total = 11 - total % 11;
1076  if (total == 11) {total = 0;}
1077  if (total < 10) {  
1078  
1079    // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1080    if (total == vatnumber.slice (8,9)) 
1081      return true
1082    else 
1083      return false;
1084  }
1085}
1086
1087function PLVATCheckDigit (vatnumber) {
1088
1089  // Checks the check digits of a Polish VAT number.
1090  
1091  var total = 0;
1092  var multipliers = [6,5,7,2,3,4,5,6,7];
1093  
1094  // Extract the next digit and multiply by the counter.
1095  for (var i = 0; i < 9; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1096  
1097  // Establish check digits subtracting modulus 11 from 11.
1098  total = total % 11;
1099  if (total > 9) {total = 0;};
1100  
1101  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1102  if (total == vatnumber.slice (9,10)) 
1103    return true
1104  else 
1105    return false;
1106}
1107
1108function PTVATCheckDigit (vatnumber) {
1109
1110  // Checks the check digits of a Portugese VAT number.
1111  
1112  var total = 0;
1113  var multipliers = [9,8,7,6,5,4,3,2];
1114  
1115  // Extract the next digit and multiply by the counter.
1116  for (var i = 0; i < 8; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1117  
1118  // Establish check digits subtracting modulus 11 from 11.
1119  total = 11 - total % 11;
1120  if (total > 9) {total = 0;};
1121  
1122  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1123  if (total == vatnumber.slice (8,9)) 
1124    return true
1125  else 
1126    return false;
1127}
1128
1129function ROVATCheckDigit (vatnumber) {
1130
1131  // Checks the check digits of a Romanian VAT number.
1132  
1133  var multipliers = [7,5,3,2,1,7,5,3,2];
1134  
1135  // Extract the next digit and multiply by the counter.
1136  var VATlen = vatnumber.length;
1137  multipliers = multipliers.slice (10-VATlen);
1138  var total = 0;
1139  for (var i = 0; i < vatnumber.length-1; i++) {
1140    total += Number(vatnumber.charAt(i)) * multipliers[i];
1141  }  
1142  
1143  // Establish check digits by getting modulus 11.
1144  total = (10 * total) % 11;
1145  if (total == 10) total = 0; 
1146  
1147  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1148  if (total == vatnumber.slice (vatnumber.length-1, vatnumber.length))
1149    return true
1150  else 
1151    return false;
1152}
1153
1154function RSVATCheckDigit (vatnumber) {
1155
1156  // Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.
1157  
1158  var product = 10;
1159  var sum = 0;     
1160  var checkdigit = 0; 
1161  
1162  for (var i = 0; i < 8; i++) {
1163    
1164    // Extract the next digit and implement the algorithm
1165    sum = (Number(vatnumber.charAt(i)) + product) % 10;
1166    if (sum == 0) {sum = 10};
1167    product = (2 * sum) % 11;
1168  }
1169  
1170  // Now check that we have the right check digit
1171  if ((product + vatnumber.slice (8,9)*1) % 10== 1)
1172    return true
1173  else 
1174    return false;
1175}
1176function RUVATCheckDigit (vatnumber) {
1177
1178  // Checks the check digits of a Russian INN number 
1179  // See http://russianpartner.biz/test_inn.html for algorithm 
1180 
1181  // 10 digit INN numbers
1182	if (vatnumber.length == 10) {
1183		var total = 0;
1184		var multipliers = [2,4,10,3,5,9,4,6,8,0]
1185		for (var i = 0; i < 10; i++) {
1186			total += Number(vatnumber.charAt(i)) * multipliers[i];
1187		}
1188		total = total % 11
1189		if (total > 9) {total = total % 10} 
1190    
1191		// Compare it with the last character of the VAT number. If it is the same, then it's valid
1192		if (total == vatnumber.slice (9,10)) 
1193			return true
1194		else 
1195			return false
1196   
1197  // 12 digit INN numbers
1198	} else if(vatnumber.length == 12){
1199		var total1 = 0
1200		var multipliers1 = [7,2,4,10,3,5,9,4,6,8,0]
1201		var total2 = 0
1202		var multipliers2 = [3,7,2,4,10,3,5,9,4,6,8,0]
1203		
1204		for (var i = 0; i < 11; i++) total1 += Number(vatnumber.charAt(i)) * multipliers1[i];
1205		total1 = total1 % 11
1206		if (total1 > 9) {total1 = total1 % 10} 
1207		
1208		for (var i = 0; i < 11; i++) total2 += Number(vatnumber.charAt(i)) * multipliers2[i];
1209		total2 = total2 % 11
1210		if (total2 > 9) {total2 = total2 % 10}  
1211		
1212		// Compare the first check with the 11th character and the second check with the 12th and last 
1213    // character of the VAT number. If they're both the same, then it's valid
1214		if ((total1 == vatnumber.slice (10,11)) && (total2 == vatnumber.slice (11,12)))
1215			return true
1216		else 
1217			return false
1218	}
1219}
1220
1221function SEVATCheckDigit (vatnumber) {
1222
1223  // Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
1224  var R = 0;
1225  var digit;
1226  for (var i = 0; i < 9; i=i+2) {
1227    digit = Number(vatnumber.charAt(i));
1228    R += Math.floor(digit / 5)  + ((digit * 2) % 10);
1229  }
1230  
1231  // Calculate S where S = C2 + C4 + C6 + C8
1232  var S = 0;
1233  for (var i = 1; i < 9; i=i+2) S += Number(vatnumber.charAt(i));
1234  
1235  // Calculate the Check Digit
1236  var cd = (10 - (R + S) % 10) % 10;  
1237  
1238  // Compare it with the last character of the VAT number. If it's the same, then it's valid.
1239  if (cd == vatnumber.slice (9,10)) 
1240    return true
1241  else 
1242    return false;
1243}
1244
1245function SIVATCheckDigit (vatnumber) {
1246
1247  // Checks the check digits of a Slovenian VAT number.
1248  
1249  var total = 0; 
1250  var multipliers = [8,7,6,5,4,3,2];
1251  
1252  // Extract the next digit and multiply by the counter.
1253  for (var i = 0; i < 7; i++) total += Number(vatnumber.charAt(i)) * multipliers[i];
1254  
1255  // Establish check digits using modulus 11
1256  total = 11 - total % 11;
1257  if (total == 10) {total = 0;};  
1258  
1259  // Compare the number with the last character of the VAT number. If it is the 
1260  // same, then it's a valid check digit.
1261  if (total != 11 && total == vatnumber.slice (7,8)) 
1262    return true
1263  else 
1264    return false;
1265}
1266
1267function SKVATCheckDigit (vatnumber) {
1268
1269  // Checks the check digits of a Slovakian VAT number.
1270  
1271  // Check that the modulus of the whole VAT number is 0 - else error
1272  if (Number(vatnumber % 11) == 0) 
1273    return true
1274  else 
1275    return false
vendor: 4 bytes, lines 1275-1276
1275;
1276}

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.