PageSourceSearch

https://www.naturastore.pt/checkout/v1/lib/jsvat/jsvat.js?10

js naturastore.pt collected 2026-09-26 13:15:40 UTC 46,568 bytes, 1,448 lines download raw bytes

1function checkVATNumber(toCheck, country_code, distrito) {
2  var taxIdentifier = toCheck.replace(country_code, '');
3
4  if (taxIdentifier !== '' && !/^[A-Za-z0-9]+$/.test(taxIdentifier)) {
5    var invalidResult = {
6      valid_country: true,
7      valid_vat: false,
8      status: 0,
9      address: null
10    };
11
12    return distrito === undefined ? invalidResult : Promise.resolve(invalidResult);
13  }
14  
15  if(distrito === undefined) {
16    //console.log('checkVATNumber (1)')
17    var xhr = new XMLHttpRequest();
18    var url = `/checkout/v1/ajax_validar_nif.php?cc=${country_code}&nif=${taxIdentifier}&distrito=`;
19    xhr.open("GET", url, false);
20    xhr.withCredentials = true;
21    xhr.send(null);
22    
23    var xhr_resp = $.parseJSON(xhr.response);
24    return getNITStatusResult(xhr_resp);
25  }
26
27  //console.log('checkVATNumber (2)')
28
29  return new Promise(function(resolve, reject) {
30    $.ajax({
31      url: `/checkout/v1/ajax_validar_nif.php?cc=${country_code}&nif=${taxIdentifier}&distrito=${distrito}`
32    }).done(function(xhr) {
33      resolve($.parseJSON(xhr));
34
35    }).fail(function(error) {
36      console.error(error);
37      reject(error);
38      
39    });
40
41  }).then(function(xhr_resp) {
42    return getNITStatusResult(xhr_resp);
43  });
44}
45
46function getNITStatusResult(xhr_resp) {
47  if(xhr_resp.status == 2) {
48    location.reload();
49    return false;
50  }
51
52  if(xhr_resp.is_valid == true || xhr_resp.status == 3 || xhr_resp.pf != 1) { // pf (1 = B2B)
53    return {
54      valid_country: true,
55      valid_vat: xhr_resp.is_valid,
56      status: xhr_resp.status || 0,
57      address: xhr_resp.address || null
58    };
59
60  } else {
61    return {
62      valid_country: false,
63      valid_vat: false,
64      status: xhr_resp.status || 0,
65      address: null
66    };
67
68  }
69
70  // Array holds the regular expressions for the valid VAT number
71  var vatexp = new Array ();
72  
73  // To change the default country (e.g. from the UK to Germany - DE):
74  //    1.  Change the country code in the defCCode variable below to "DE".
75  //    2.  Remove the question mark from the regular expressions associated with the UK VAT number: 
76  //        i.e. "(GB)?" -> "(GB)"
77  //    3.  Add a question mark into the regular expression associated with Germany's number 
78  //        following the country code: i.e. "(DE)" -> "(DE)?"
79  
80  var defCCode = "GB";
81  
82  if (country_code) country_code = country_code.replace(/\s*/gi,"").toUpperCase();
83
84  // CUSTOM
85  //toCheck = toCheck.replace(/\s*/gi,"");
86
87  // Note - VAT codes without the "**" in the comment do not have check digit checking.
88
89  vatexp.push (/^(AT)U(\d{8})$/);                           //** Austria
90  vatexp.push (/^(BE)(0?\d{9})$/);                          //** Belgium 
91  vatexp.push (/^(BG)(\d{9,10})$/);                         //** Bulgaria 
92  vatexp.push (/^(CH)E(\d{9})((MWST)|(IVA)|(TVA))/);        // Switzerland
93  vatexp.push (/^(CY)([0-5|9]\d{7}[A-Z])$/);                //** Cyprus
94  vatexp.push (/^(CZ)(\d{8,10})(\d{3})?$/);                 //** Czech Republic
95  vatexp.push (/^(DE)([1-9]\d{8})$/);                       //** Germany 
96  vatexp.push (/^(DK)((\d{8}))$/);                          //** Denmark 
97  vatexp.push (/^(EE)(10\d{7})$/);                          //** Estonia 
98  vatexp.push (/^(EL)(\d{9})$/);                            //** Greece 
99  vatexp.push (/^(ES)([A-Z]\d{8})$/);                       //** Spain (National juridical entities)
100  vatexp.push (/^(ES)([A-H|N-S|W]\d{7}[A-J])$/);            //** Spain (Other juridical entities)
101  vatexp.push (/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/);
101              //** Spain (Personal entities type 1)
102  vatexp.push (/^(ES)([K|L|M|X]\d{7}[A-Z])$/);              //** Spain (Personal entities type 2)
103  vatexp.push (/^(EU)(\d{9})$/);                            //** EU-type 
104  vatexp.push (/^(FI)(\d{8})$/);                            //** Finland 
105  vatexp.push (/^(FR)(\d{11})$/);                           //** France (1)
106  vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]\d{10}$/);          // France (2)
107  vatexp.push (/^(FR)\d[(A-H)|(J-N)|(P-Z)]\d{9}$/);         // France (3)
108  vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]{2}\d{9}$/);        // France (4)
109  vatexp.push (/^(GB)?(\d{9})$/);                           //** UK (Standard)
110  vatexp.push (/^(GB)?(\d{12})$/);                          //** UK (Branches)
111  vatexp.push (/^(GB)?(GD\d{3})$/);                         //** UK (Government)
112  vatexp.push (/^(GB)?(HA\d{3})$/);                         //** UK (Health authority)
113  vatexp.push (/^(GR)(\d{8,9})$/);                          //** Greece 
114  vatexp.push (/^(HR)(\d{11})$/);                           //** Croatia 
115  vatexp.push (/^(HU)(\d{8})$/);                            //** Hungary 
116  vatexp.push (/^(IE)(\d{7}[A-W])$/);                       //** Ireland (1)
117  vatexp.push (/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/);        //** Ireland (2)
118  vatexp.push (/^(IT)(\d{11})$/);                           //** Italy 
119  vatexp.push (/^(LV)(\d{11})$/);                           //** Latvia 
120  vatexp.push (/^(LT)(\d{9}|\d{12})$/);                     //** Lithunia
121  vatexp.push (/^(LU)(\d{8})$/);                            //** Luxembourg 
122  vatexp.push (/^(MT)([1-9]\d{7})$/);                       //** Malta
123  vatexp.push (/^(NL)(\d{9})B\d{2}$/);                      //** Netherlands
124  vatexp.push (/^(PL)(\d{10})$/);                           //** Poland
125  vatexp.push (/^(PT)(\d{9})$/);                            //** Portugal
126  vatexp.push (/^(RO)([1-9]\d{1,9})$/);                     //** Romania
127  vatexp.push (/^(SI)([1-9]\d{7})$/);                       //** Slovenia
128  vatexp.push (/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/);        //** Slovakia Republic
129  vatexp.push (/^(SE)(\d{10}01)$/);                         //** Sweden
130
131  // Load up the string to check
132  var VATNumber = toCheck.toUpperCase();
133  
134  // Remove spaces from the VAT number to help validation
135  // CUSTOM
136  /*
137  var chars = [" ","-",",","."];
138  for ( var i=0; i<chars.length; i++) {
139    while (VATNumber.indexOf(chars[i])!= -1) {
140      VATNumber = VATNumber.slice (0,VATNumber.indexOf(chars[i])) + VATNumber.slice (VATNumber.indexOf(chars[i])+1);
141    }
142  }
143  */
144
145  var valid = false;                         
146  var valid_country = false;
147  if (country_code) {
148    switch (country_code) {     
149      case "AT":
150        if (country_code == "AT") {
151          valid_country = true;
152        }
153       break;        
154      case "BE":
155        if (country_code == "BE") {
156          valid_country = true;
157        }
158        break;          
159      case "BG":
160        if (country_code == "BG") {
161          valid_country = true;
162        }
163        break;
164      case "CH":
165        if (country_code == "CH") {
166          valid_country = true;
167        }             
168      case "CY":
169        if (country_code == "CY") {
170          valid_country = true;
171        }
172        break;          
173      case "CZ":
174        if (country_code == "CZ") {
175          valid_country = true;          
176        }
177        break;      
178      case "DE":
179        if (country_code == "DE") {
180          valid_country = true;
181        }
182        break;       
183      case "DK":
184        if (country_code == "DK") {
185          valid_country = true;
186        }
187        break;                 
188      case "EE":
189        if (country_code == "EE") {
190          valid_country = true;
191        }
192        break;             
193      case "EL":
194        if (country_code == "GR") {
195          valid_country = true;
196        }
197        break;       
198      case "ES":
199        if (country_code == "ES") {
200          valid_country = true;
201        }
202        break;       
203      case "EU":
204        if (country_code == "EU") {
205          valid_country = true;
206        }
207        break;       
208      case "FI":
209        if (country_code == "FI") {
210          valid_country = true;
211        }
212        break;        
213      case "FR":
214        if (
215           country_code == "FR"
216        || country_code == "GF"
217        || country_code == "PF"
218        || country_code == "TF") {
219          valid_country = true;
220        }
221        break;         
222      case "GB":
223        if (country_code == "GB") {
224          valid_country = true;
225        }
226        break;                     
227      case "GR":
228        if (country_code == "GR") {
229          valid_country = true;
230        }
231        break;               
232      case "HR":
233        if (country_code == "HR") {
234          valid_country = true;
235        }
236        break;            
237      case "HU":
238        if (country_code == "HU") {
239          valid_country = true;
240        }
241        break;         
242      case "IE":
243        if (country_code == "IE") {
244          valid_country = true;
245        }
246        break;              
247      case "IT":
248        if (country_code == "IT") {
249          valid_country = true;
250        }
251        break;            
252      case "LT":
253        if (country_code == "LT") {
254          valid_country = true;
255        }
256        break;            
257      case "LU":
258        if (country_code == "LU") {
259          valid_country = true;
260        }
261        break;            
262      case "LV":
263        if (country_code == "LV") {
264          valid_country = true;
265        }
266        break;             
267      case "MT":
268        if (country_code == "MT") {
269          valid_country = true;
270        }
271        break;           
272      case "NL":
273        if (country_code == "NL") {
274          valid_country = true;
275        }
276        break;            
277      case "PL":    
278       if (country_code == "PL") {
279          valid_country = true;  
280        }
281        break;         
282      case "PT":
283        if (country_code == "PT") {
284          valid_country = true;
285        }
286        break;           
287      case "RO":
288        if (country_code == "RO") {
289          valid_country = true;
290        }
291        break;       
292      case "SE":
293        if (country_code == "SE") {
294          valid_country = true;
295        }
296        break;        
297      case "SI":
298        if (country_code == "SI") {
299          valid_country = true;
300        }
301        break;         
302      case "SK":
303        if (country_code == "SK") {
304          valid_country = true;
305        }
306        break; 
307      default:
308        valid_country = false;
309    }
310  } 
311
312  // Check the string against the types of VAT numbers
313  for (i=0; i<vatexp.length; i++) {
314    if (vatexp[i].test(VATNumber)) {
315      
316      var cCode = RegExp.$1;                             // Isolate country code
317      var cNumber = RegExp.$2;                           // Isolate the number
318      if (cCode.length == 0) cCode = defCCode;           // Set up default country code
319      
320      // Now look at the check digits for those countries we know about.
321      switch (cCode) {     
322        case "AT":
323            valid = ATVATCheckDigit (cNumber);
324            valid_country = (!country_code || country_code == "AT");
325          break;        
326        case "BE":
327            valid = BEVATCheckDigit (cNumber);
328            valid_country = (!country_code || country_code == "BE");
329          break;          
330        case "BG":
331            valid = BGVATCheckDigit (cNumber);
332            valid_country = (!country_code || country_code == "BG");
333          break;
334        case "CH":
335            valid = CHVATCheckDigit (cNumber);
336            valid_country = (!country_code || country_code == "CH");
337          break;             
338        case "CY":
339            valid = CYVATCheckDigit (cNumber);
340            valid_country = (!country_code || country_code == "CY");
341          break;          
342        case "CZ": 
343            valid = CZVATCheckDigit (cNumber);
344            valid_country = (!country_code || country_code == "CZ");
345          break;      
346        case "DE":
347            valid = DEVATCheckDigit (cNumber);
348            valid_country = (!country_code || country_code == "DE");
349          break;       
350        case "DK":
351            valid = DKVATCheckDigit (cNumber);
352            valid_country = (!country_code || country_code == "DK");
353          break;                 
354        case "EE":
355            valid = EEVATCheckDigit (cNumber);
356            valid_country = (!country_code || country_code == "EE");
357          break;             
358        case "EL":
359            valid = ELVATCheckDigit (cNumber);
360            valid_country = (!country_code || country_code == "GR");
361          break;       
362        case "ES":
363            valid = ESVATCheckDigit (cNumber);
364            valid_country = (!country_code || country_code == "ES");
365          break;       
366        case "EU":
367            valid = EUVATCheckDigit (cNumber);
368            valid_country = (!country_code || country_code == "EU");
369          break;       
370        case "FI":
371            valid = FIVATCheckDigit (cNumber);
372            valid_country = (!country_code || country_code == "FI");
373          break;        
374        case "FR":
375            valid = FRVATCheckDigit (cNumber);
376            valid_country = (!country_code || country_code == "FR" || country_code == "GF"|| country_code == "PF" || country_code == "TF");
377          break;         
378        case "GB":
379            valid = UKVATCheckDigit (cNumber);
380            valid_country = (!country_code || country_code == "GB");
381          break;                     
382        case "GR":
383            valid = ELVATCheckDigit (cNumber);
384             valid_country = (!country_code || country_code == "GR");
385          break;               
386        case "HR":
387            valid = HRVATCheckDigit (cNumber);
388            valid_country = (!country_code || country_code == "HR");
389          break;            
390        case "HU":
391            valid = HUVATCheckDigit (cNumber);
392            valid_country = (!country_code || country_code == "HU");
393          break;         
394        case "IE":
395            valid = IEVATCheckDigit (cNumber);
396            valid_country = (!country_code || country_code == "IE");
397          break;              
398        case "IT":
399            valid = ITVATCheckDigit (cNumber);
400            valid_country = (!country_code || country_code == "IT");
401          break;            
402        case "LT":
403            valid = LTVATCheckDigit (cNumber);
404            valid_country = (!country_code || country_code == "LT");
405          break;            
406        case "LU":
407            valid = LUVATCheckDigit (cNumber);
408            valid_country = (!country_code || country_code == "LU");
409          break;            
410        case "LV":
411            valid = LVVATCheckDigit (cNumber);
412            valid_country = (!country_code || country_code == "LV");
413          break;             
414        case "MT":
415            valid = MTVATCheckDigit (cNumber);
416            valid_country = (!country_code || country_code == "MT");
417          break;           
418        case "NL":
419            valid = NLVATCheckDigit (cNumber);
420            valid_country = (!country_code || country_code == "NL");
421          break;            
422        case "PL":    
423            valid = PLVATCheckDigit (cNumber);
424            valid_country = (!country_code || country_code == "PL");
425          break;         
426        case "PT":
427            valid = PTVATCheckDigit (cNumber);
428            valid_country = (!country_code || country_code == "PT");
429          break;           
430        case "RO":
431            valid = ROVATCheckDigit (cNumber);
432            valid_country = (!country_code || country_code == "RO");
433          break;       
434        case "SE":
435            valid = SEVATCheckDigit (cNumber);
436            valid_country = (!country_code || country_code == "SE");
437          break;        
438        case "SI":
439            valid = SIVATCheckDigit (cNumber);
440            valid_country = (!country_code || country_code == "SI");
441          break;         
442        case "SK":
443            valid = SKVATCheckDigit (cNumber);
444            valid_country = (!country_code || country_code == "SK");
445          break;  
446        default: 
447          if (country_code) {
448            valid = false;
449          } else {
450            valid = true;
451          }
452          break;   
453      }
454            
455      // We have found that the number is valid - break from loop
456      break;
457    }
458  }
459  
460  // Return with either an error or the reformatted VAT number
461  return { 
462    valid_country: valid_country, 
463    valid_vat: valid, 
464    number: VATNumber 
465  };
466}
467
468function ATVATCheckDigit (vatnumber) {
469
470  // Checks the check digits of an Austrian VAT number.
471  
472  var total = 0;
473  var multipliers = [1,2,1,2,1,2,1];
474  var temp = 0;
475  
476  // Extract the next digit and multiply by the appropriate multiplier.  
477  for (var i = 0; i < 7; i++) {
478    temp = Number(vatnumber.charAt(i)) * multipliers[i];
479    if (temp > 9)
480      total = total + Math.floor(temp/10) + temp%10
481    else
482      total = total + temp;
483  }  
484  
485  // Establish check digit.
486  total = 10 - (total+4) % 10; 
487  if (total == 10) total = 0;
488  
489  // Compare it with the last character of the VAT number. If it is the same, 
490  // then it's a valid check digit.
491  if (total == vatnumber.slice (7,8)) 
492    return true
493  else 
494    return false;
495}
496
497function BEVATCheckDigit (vatnumber) {
498
499  // Checks the check digits of a Belgium VAT number.
500  
501  // Nine digit numbers have a 0 inserted at the front.
502  if (vatnumber.length == 9) vatnumber = "0" + vatnumber;
503  
504  if (vatnumber.slice(1,2) == 0) return false;
505  
506  // Modulus 97 check on last nine digits
507  if (97 - vatnumber.slice (0,8) % 97 == vatnumber.slice (8,10)) 
508    return true
509  else 
510    return false;
511}
512
513function BGVATCheckDigit (vatnumber) {
514
515  // Checks the check digits of a Bulgarian VAT number.
516
517  if (vatnumber.length == 9) {
518  
519    // Check the check digit of 9 digit Bulgarian VAT numbers.
520    var total = 0;
521    
522    // First try to calculate the check digit using the first multipliers  
523    var temp = 0;
524    for (var i = 0; i < 8; i++) temp = temp + Number(vatnumber.charAt(i)) * (i+1);
525    
526    // See if we have a check digit yet
527    total = temp % 11; 
528    if (total != 10) {
529      if (total == vatnumber.slice (8)) 
530        return true
531      else 
532        return false;
533    }
534  
535    // We got a modulus of 10 before so we have to keep going. Calculate the new check digit using the 
536    // different multipliers  
537    var temp = 0;
538    for (var i = 0; i < 8; i++) temp = temp + Number(vatnumber.charAt(i)) * (i+3);
539    
540    // See if we have a check digit yet. If we still have a modulus of 10, set it to 0.
541    total = temp % 11; 
542    if (total == 10) total = 0;
543    if (total == vatnumber.slice (8)) 
544      return true
545    else 
546      return false;
547  }
548  
549  // 10 digit VAT code - see if it relates to a standard physical person
550  if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vatnumber)) {
551  
552    // Check month
553    var month = Number(vatnumber.slice(2,4));
554    if ((month > 0 && month < 13) || (month > 20 & month < 33)) {
555    
556      // Extract the next digit and multiply by the counter.
557      var multipliers = [2,4,8,5,10,9,7,3,6];    
558      var total = 0;
559      for (var i = 0; i < 9; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
560      
561      // Establish check digit.
562      total = total % 11;
563      if (total == 10) total = 0;  
564      
565      // Check to see if the check digit given is correct, If not, try next type of person
566      if (total == vatnumber.substr (9,1)) return true;
567    }
568  }
569  
570  // It doesn't relate to a standard physical person - see if it relates to a foreigner.
571  
572  // Extract the next digit and multiply by the counter.
573  var multipliers = [21,19,17,13,11,9,7,3,1];    
574  var total = 0;
575  for (var i = 0; i < 9; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
576  
577  // Check to see if the check digit given is correct, If not, try next type of person
578  if (total % 10 == vatnumber.substr (9,1)) return true;
579  
580  // Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
581  
582  // Extract the next digit and multiply by the counter.
583  var multipliers = [4,3,2,7,6,5,4,3,2];    
584  var total = 0;
585  for (var i = 0; i < 9; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
586  
587  // Establish check digit.
588  total = 11 - total % 11;
589  if (total == 10) return false;  
590  if (total == 11) total = 0;  
591  
592  // Check to see if the check digit given is correct, If not, we have an error with the VAT number
593  if (total == vatnumber.substr (9,1)) 
594    return true;
595  else
596    return false;
597}
598
599function CHVATCheckDigit (vatnumber) {
600
601  // Checks the check digits of a Swiss VAT number.
602  
603  var total = 0;
604  var multipliers = [5,4,3,2,7,6,5,4];
605  
606  // Extract the next digit and multiply by the appropriate multiplier.  
607  for (var i = 0; i < 8; i++) {
608    total = total + Number(vatnumber.charAt(i)) * multipliers[i];
609  }  
610  
611  // Establish check digit.
612  total = (11 - (total % 11)) % 11;
613  
614  // Compare it with the last character of the VAT number. If it is the same, 
615  // then it's a valid check digit.
616  if (total == vatnumber.slice (8,9)) 
617    return true
618  else 
619    return false;
620}
621
622function CYVATCheckDigit (vatnumber) {
623
624  // Checks the check digits of a Cypriot VAT number.
625  
626  // Not allowed to start with '12'
627  if (Number(vatnumber.slice(0,2) == 12)) return false;
628  
629  // Extract the next digit and multiply by the counter.
630  var total = 0;
631  for (var i = 0; i < 8; i++) {
632    var temp = Number(vatnumber.charAt(i));
633    if (i % 2 == 0) {
634      switch (temp) {
635        case 0: temp = 1; break;
636        case 1: temp = 0; break;
637        case 2: temp = 5; break;
638        case 3: temp = 7; break;
639        case 4: temp = 9; break;
640        default: temp = temp*2 + 3;
641      }
642    }
643    total = total + temp;
644  }
645  
646  // Establish check digit using modulus 26, and translate to char. equivalent.
647  total = total % 26;
648  total = String.fromCharCode(total+65);
649  
650  // Check to see if the check digit given is correct
651  if (total == vatnumber.substr (8,1)) 
652    return true 
653  else 
654    return false;
655}
656
657function CZVATCheckDigit (vatnumber) {
658
659  // Checks the check digits of a Czech Republic VAT number.
660  
661  var total = 0;
662  var multipliers = [8,7,6,5,4,3,2];
663  
664  var czexp = new Array ();
665  czexp[0] = (/^\d{8}$/);
666  czexp[1] = (/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/);
667  czexp[2] = (/^6\d{8}$/);
668  czexp[3] = (/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/);
669  var i = 0;
670  
671  // Legal entities
672  if (czexp[0].test(vatnumber)) {    
673    
674    // Extract the next digit and multiply by the counter.
675    for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
676    
677    // Establish check digit.
678    total = 11 - total % 11;
679    if (total == 10) total = 0; 
680    if (total == 11) total = 1; 
681    
682    // Compare it with the last character of the VAT number. If it is the same, 
683    // then it's a valid check digit.
684    if (total == vatnumber.slice (7,8)) 
685      return true
686    else 
687      return false;
688  }  
689  
690  // Individuals type 1
691  else if (czexp[1].test(vatnumber)) {
692    if (temp = Number(vatnumber.slice(0,2)) > 53) return false;
693    return true;
694  }
695  
696  // Individuals type 2
697  else if (czexp[2].test(vatnumber)) {  
698    
699    // Extract the next digit and multiply by the counter.
700    for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i+1)) * multipliers[i];
701    
702    // Establish check digit.
703    total = 11 - total % 11;
704    if (total == 10) total = 0; 
705    if (total == 11) total = 1; 
706    
707    // Convert calculated check digit according to a lookup table;
708    var lookup  = [8,7,6,5,4,3,2,1,0,9,10];
709    if (lookup[total-1] == vatnumber.slice (8,9)) 
710      return true
711    else 
712      return false;
713  }
714  
715  // Individuals type 3
716  else if (czexp[3].test(vatnumber)) {
717    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));
718    if (temp % 11 == 0 && Number(vatnumber) % 11 == 0)
719      return true
720    else
721      return false;
722  }
723  
724  // else error
725  return false;
726}
727
728function DEVATCheckDigit (vatnumber) {
729
730  // Checks the check digits of a German VAT number.
731  
732  var product = 10;
733  var sum = 0;     
734  var checkdigit = 0;                      
735  for (var i = 0; i < 8; i++) {
736    
737    // Extract the next digit and implement peculiar algorithm!.
738    sum = (Number(vatnumber.charAt(i)) + product) % 10;
739    if (sum == 0) {sum = 10};
740    product = (2 * sum) % 11;
741  }
742  
743  // Establish check digit.  
744  if (11 - product == 10) {checkdigit = 0} else {checkdigit = 11 - product};
745  
746  // Compare it with the last two characters of the VAT number. If the same, then it is a valid 
747  // check digit.
748  if (checkdigit == vatnumber.slice (8,9))
749    return true
750  else 
751    return false;
752}
753
754function DKVATCheckDigit (vatnumber) {
755
756  // Checks the check digits of a Danish VAT number.
757  
758  var total = 0;
759  var multipliers = [2,7,6,5,4,3,2,1];
760  
761  // Extract the next digit and multiply by the counter.
762  for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
763  
764  // Establish check digit.
765  total = total % 11;
766  
767  // The remainder should be 0 for it to be valid..
768  if (total == 0) 
769    return true
770  else 
771    return false;
772}
773
774function EEVATCheckDigit (vatnumber) {
775
776  // Checks the check digits of an Estonian VAT number.
777  
778  var total = 0;
779  var multipliers = [3,7,1,3,7,1,3,7];
780  
781  // Extract the next digit and multiply by the counter.
782  for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
783  
784  // Establish check digits using modulus 10.
785  total = 10 - total % 10;
786  if (total == 10) total = 0;
787  
788  // Compare it with the last character of the VAT number. If it is the same, 
789  // then it's a valid check digit.
790  if (total == vatnumber.slice (8,9))
791    return true
792  else 
793    return false;
794}
795
796function ELVATCheckDigit (vatnumber) {
797
798  // Checks the check digits of a Greek VAT number.
799  
800  var total = 0;
801  var multipliers = [256,128,64,32,16,8,4,2];
802  
803  //eight character numbers should be prefixed with an 0.
804  if (vatnumber.length == 8) {vatnumber = "0" + vatnumber};
805  
806  // Extract the next digit and multiply by the counter.
807  for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
808  
809  // Establish check digit.
810  total = total % 11;
811  if (total > 9) {total = 0;};  
812  
813  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
814  // check digit.
815  if (total == vatnumber.slice (8,9)) 
816    return true
817  else 
818    return false;
819}
820
821function ESVATCheckDigit (vatnumber) {
822
823  // Checks the check digits of a Spanish VAT number.
824  
825  var total = 0; 
826  var temp = 0;
827  var multipliers = [2,1,2,1,2,1,2];
828  var esexp = new Array ();
829  esexp[0] = (/^[A-H|J|U|V]\d{8}$/);
830  esexp[1] = (/^[A-H|N-S|W]\d{7}[A-J]$/);
831  esexp[2] = (/^[0-9|Y|Z]\d{7}[A-Z]$/);
832  esexp[3] = (/^[K|L|M|X]\d{7}[A-Z]$/);
833  var i = 0;
834  
835  // National juridical entities
836  if (esexp[0].test(vatnumber)) {
837  
838    // Extract the next digit and multiply by the counter.
839    for (i = 0; i < 7; i++) {
840      temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
841      if (temp > 9) 
842        total = total + Math.floor(temp/10) + temp%10 
843      else 
844        total = total + temp;
845    }   
846    // Now calculate the check digit itself. 
847    total = 10 - total % 10;
848    if (total == 10) {total = 0;}
849    
850    // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
851    // check digit.
852    if (total == vatnumber.slice (8,9)) 
853      return true
854    else 
855      return false;
856  }
857  
858  // Juridical entities other than national ones
859  else if (esexp[1].test(vatnumber)) {
860  
861    // Extract the next digit and multiply by the counter.
862    for (i = 0; i < 7; i++) {
863      temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
864      if (temp > 9) 
865        total = total + Math.floor(temp/10) + temp%10 
866      else 
867        total = total + temp;
868    }    
869    
870    // Now calculate the check digit itself.
871    total = 10 - total % 10;
872    total = String.fromCharCode(total+64);
873    
874    // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
875    // check digit.
876    if (total == vatnumber.slice (8,9)) 
877      return true
878    else 
879      return false;
880  }
881  
882  // Personal number (NIF) (starting with numeric of Y or Z)
883  else if (esexp[2].test(vatnumber)) {
884    var tempnumber = vatnumber;
885    if (tempnumber.substring(0,1) == 'Y') tempnumber = tempnumber.replace (/Y/, "1");
886    if (tempnumber.substring(0,1) == 'Z') tempnumber = tempnumber.replace (/Z/, "2");
887    return tempnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(tempnumber.substring(0,8)) % 23);
888  }
889  
890  // Personal number (NIF) (starting with K, L, M, or X)
891  else if (esexp[3].test(vatnumber)) {
892    return vatnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(vatnumber.substring(1,8)) % 23);
893  }
894  
895  else return false;
896}
897
898function EUVATCheckDigit (vatnumber) {
899
900  // We know litle about EU numbers apart from the fact that the first 3 digits represent the 
901  // country, and that there are nine digits in total.
902  return true;
903}
904
905function FIVATCheckDigit (vatnumber) {
906
907  // Checks the check digits of a Finnish VAT number.
908  
909  var total = 0; 
910  var multipliers = [7,9,10,5,8,4,2];
911  
912  // Extract the next digit and multiply by the counter.
913  for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
914  
915  // Establish check digit.
916  total = 11 - total % 11;
917  if (total > 9) {total = 0;};  
918  
919  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
920  // check digit.
921  if (total == vatnumber.slice (7,8)) 
922    return true
923  else 
924    return false;
925}
926
927function FRVATCheckDigit (vatnumber) {
928
929  // Checks the check digits of a French VAT number.
930  
931  if (!(/^\d{11}$/).test(vatnumber)) return false;
932  
933  // Extract the last nine digits as an integer.
934  var total = vatnumber.substring(2); 
935  
936  // Establish check digit.
937  total = (total*100+12) % 97;
938  
939  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
940  // check digit.
941  if (total == vatnumber.slice (0,2)) 
942    return true
943  else 
944    return false;
945}
946
947function HRVATCheckDigit (vatnumber) {
948
949  // Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
950  
951  var product = 10;
952  var sum = 0;     
953  var checkdigit = 0; 
954  
955  for (var i = 0; i < 10; i++) {
956    
957    // Extract the next digit and implement the algorithm
958    sum = (Number(vatnumber.charAt(i)) + product) % 10;
959    if (sum == 0) {sum = 10};
960    product = (2 * sum) % 11;
961  }
962  
963  // Now check that we have the right check digit
964  if ((product + vatnumber.slice (10,11)*1) % 10== 1)
965    return true
966  else 
967    return false;
968}
969
970function HUVATCheckDigit (vatnumber) {
971
972  // Checks the check digits of a Hungarian VAT number.
973  
974  var total = 0;
975  var multipliers = [9,7,3,1,9,7,3];
976  
977  // Extract the next digit and multiply by the counter.
978  for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
979  
980  // Establish check digit.
981  total = 10 - total % 10; 
982  if (total == 10) total = 0;
983  
984  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
985  // check digit.
986  if (total == vatnumber.slice (7,8)) 
987    return true
988  else 
989    return false;
990}
991
992function IEVATCheckDigit (vatnumber) {
993
994  // Checks the check digits of an Irish VAT number.
995  
996  var total = 0; 
997  var multipliers = [8,7,6,5,4,3,2];
998  
999  // If the code is in the old format, we need to convert it to the new.
1000  if (/^\d[A-Z\*\+]/.test(vatnumber)) vatnumber = "0" + vatnumber.substring(2,7) + vatnumber.substring(0,1) + vatnumber.substring(7,8);
1001    
1002  // Extract the next digit and multiply by the counter.
1003  for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1004  
1005  // Establish check digit using modulus 23, and translate to char. equivalent.
1006  total = total % 23;
1007  if (total == 0)
1008    total = "W"
1009  else
1010    total = String.fromCharCode(total+64);
1011  
1012  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1013  // check digit.
1014  if (total == vatnumber.slice (7,8)) 
1015    return true
1016  else 
1017    return false;
1018}
1019
1020function ITVATCheckDigit (vatnumber) {
1021
1022  // Checks the check digits of an Italian VAT number.
1023  
1024  var total = 0;
1025  var multipliers = [1,2,1,2,1,2,1,2,1,2];
1026  var temp;
1027    
1028  // The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 8888
1029  if (Number(vatnumber.slice(0,7))==0) return false;
1030  temp=Number(vatnumber.slice(7,10));
1031  if ((temp<1) || (temp>201) && temp != 999 && temp != 888) return false;
1032  
1033  // Extract the next digit and multiply by the appropriate  
1034  for (var i = 0; i < 10; i++) {
1035    temp = Number(vatnumber.charAt(i)) * multipliers[i];
1036    if (temp > 9) 
1037      total = total + Math.floor(temp/10) + temp%10 
1038    else 
1039      total = total + temp;
1040  }
1041  
1042  // Establish check digit.
1043  total = 10 - total % 10;
1044  if (total > 9) {total = 0;};  
1045  
1046  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1047  // check digit.
1048  if (total == vatnumber.slice (10,11)) 
1049    return true
1050  else 
1051    return false;
1052}
1053
1054function LTVATCheckDigit (vatnumber) {
1055
1056  // Checks the check digits of a Lithuanian VAT number.
1057  
1058  // 9 character VAT numbers are for legal persons
1059  if (vatnumber.length == 9) {
1060  
1061    // 8th character must be one
1062    if (!(/^\d{7}1/).test(vatnumber)) return false;
1063    
1064    // Extract the next digit and multiply by the counter+1.
1065    var total = 0;
1066    for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * (i+1);
1067    
1068    // Can have a double check digit calculation!
1069    if (total % 11 == 10) {
1070      var multipliers = [3,4,5,6,7,8,9,1];
1071      total = 0;
1072      for (i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1073    }
1074    
1075    // Establish check digit.
1076    total = total % 11;
1077    if (total == 10) {total = 0;}; 
1078    
1079    // Compare it with the last character of the VAT number. If it is the same, 
1080    // then it's a valid check digit.
1081    if (total == vatnumber.slice (8,9)) 
1082      return true
1083    else 
1084      return false;
1085  }
1086  
1087  // 12 character VAT numbers are for temporarily registered taxpayers
1088  else {
1089  
1090    // 11th character must be one
1091    if (!(/^\d{10}1/).test(vatnumber)) return false;
1092    
1093    // Extract the next digit and multiply by the counter+1.
1094    var total = 0;
1095    var multipliers = [1,2,3,4,5,6,7,8,9,1,2];
1096    for (var i = 0; i < 11; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1097    
1098    // Can have a double check digit calculation!
1099    if (total % 11 == 10) {
1100      var multipliers = [3,4,5,6,7,8,9,1,2,3,4];
1101      total = 0;
1102      for (i = 0; i < 11; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1103    }
1104    
1105    // Establish check digit.
1106    total = total % 11;
1107    if (total == 10) {total = 0;}; 
1108    
1109    // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1110    // check digit.
1111    if (total == vatnumber.slice (11,12)) 
1112      return true
1113    else 
1114      return false;
1115  }
1116}
1117
1118function LUVATCheckDigit (vatnumber) {
1119
1120  // Checks the check digits of a Luxembourg VAT number.
1121  
1122  if (vatnumber.slice (0,6) % 89 == vatnumber.slice (6,8)) 
1123    return true
1124  else 
1125    return false;
1126}
1127
1128function LVVATCheckDigit (vatnumber) {
1129
1130  // Checks the check digits of a Latvian VAT number.
1131  
1132  // Differentiate between legal entities and natural bodies. For the latter we simplly check that
1133  // the first six digits correspond to valid DDMMYY dates.
1134  if ((/^[0-3]/).test(vatnumber)) {
1135    if ((/^[0-3][0-9][0-1][0-9]/).test(vatnumber) )
1136      return true
1137    else
1138      return false;
1139  }
1140  
1141  else {
1142  
1143    var total = 0;
1144    var multipliers = [9,1,4,8,3,10,2,5,7,6];
1145    
1146    // Extract the next digit and multiply by the counter.
1147    for (var i = 0; i < 10; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1148    
1149    // Establish check digits by getting modulus 11.
1150    if (total%11 == 4 && vatnumber[0] ==9) total = total - 45;
1151    if (total%11 == 4) 
1152      total = 4 - total%11
1153    else if (total%11 > 4) 
1154      total = 14 - total%11
1155    else if (total%11 < 4) 
1156      total = 3 - total%11;
1157    
1158    // Compare it with the last character of the VAT number. If it is the same, 
1159    // then it's a valid check digit.
1160    if (total == vatnumber.slice (10,11)) 
1161      return true
1162    else 
1163      return false;
1164  }
1165}
1166
1167function MTVATCheckDigit (vatnumber) {
1168
1169  // Checks the check digits of a Maltese VAT number.
1170  
1171  var total = 0;
1172  var multipliers = [3,4,6,7,8,9];
1173  
1174  // Extract the next digit and multiply by the counter.
1175  for (var i = 0; i < 6; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1176  
1177  // Establish check digits by getting modulus 37.
1178  total = 37 - total % 37;
1179  
1180  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1181  // check digit.
1182  if (total == vatnumber.slice (6,8) * 1) 
1183    return true
1184  else 
1185    return false;
1186}
1187
1188function NLVATCheckDigit (vatnumber) {
1189
1190  // Checks the check digits of a Dutch VAT number.
1191  
1192  var total = 0;
1193  var multipliers = [9,8,7,6,5,4,3,2];
1194  
1195  // Extract the next digit and multiply by the counter.
1196  for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1197  
1198  // Establish check digits by getting modulus 11.
1199  total = total % 11;
1200  if (total > 9) {total = 0;};  
1201  
1202  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1203  // check digit.
1204  if (total == vatnumber.slice (8,9)) 
1205    return true
1206  else 
1207    return false;
1208}
1209
1210function PLVATCheckDigit (vatnumber) {
1211
1212  // Checks the check digits of a Polish VAT number.
1213  
1214  var total = 0;
1215  var multipliers = [6,5,7,2,3,4,5,6,7];
1216  
1217  // Extract the next digit and multiply by the counter.
1218  for (var i = 0; i < 9; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1219  
1220  // Establish check digits subtracting modulus 11 from 11.
1221  total = total % 11;
1222  if (total > 9) {total = 0;};
1223  
1224  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1225  // check digit.
1226  if (total == vatnumber.slice (9,10)) 
1227    return true
1228  else 
1229    return false;
1230}
1231
1232function PTVATCheckDigit (vatnumber) {
1233
1234  // Checks the check digits of a Portugese VAT number.
1235  
1236  var total = 0;
1237  var multipliers = [9,8,7,6,5,4,3,2];
1238  
1239  // Extract the next digit and multiply by the counter.
1240  for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1241  
1242  // Establish check digits subtracting modulus 11 from 11.
1243  total = 11 - total % 11;
1244  if (total > 9) {total = 0;};
1245  
1246  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1247  // check digit.
1248  if (total == vatnumber.slice (8,9)) {
1249    //return true;
1250
1251    // CUSTOM
1252
1253    var temErro=0;
1254    if (
1255    vatnumber.substr(0,1) != '1' && // pessoa singular
1256    vatnumber.substr(0,1) != '2' && // pessoa singular
1257    vatnumber.substr(0,1) != '3' && // pessoa singular
1258    vatnumber.substr(0,2) != '45' && // pessoa singular não residente
1259    vatnumber.substr(0,1) != '5' && // pessoa colectiva
1260    vatnumber.substr(0,1) != '6' && // administração pública
1261    vatnumber.substr(0,2) != '70' && // herança indivisa
1262    vatnumber.substr(0,2) != '71' && // pessoa colectiva não residente
1263    vatnumber.substr(0,2) != '72' && // fundos de investimento
1264    vatnumber.substr(0,2) != '74' && // herança indivisa
1265    vatnumber.substr(0,2) != '75' && // herança indivisa
1266    vatnumber.substr(0,2) != '77' && // atribuição oficiosa
1267    vatnumber.substr(0,2) != '78' && // atribuição oficiosa
1268    vatnumber.substr(0,2) != '79' && // regime excepcional
1269    vatnumber.substr(0,1) != '8' && // empresário em nome individual (extinto)
1270    vatnumber.substr(0,2) != '90' && // condominios e sociedades irregulares
1271    vatnumber.substr(0,2) != '91' && // condominios e sociedades irregulares
1272    vatnumber.substr(0,2) != '98' && // não residentes
1273    vatnumber.substr(0,2) != '99' // sociedades civis
1274
1275    ) { temErro=1;}
1276    var check1 = vatnumber.substr(0,1)*9;
1277    var check2 = vatnumber.substr(1,1)*8;
1278    var check3 = vatnumber.substr(2,1)*7;
1279    var check4 = vatnumber.substr(3,1)*6;
1280    var check5 = vatnumber.substr(4,1)*5;
1281    var check6 = vatnumber.substr(5,1)*4;
1282    var check7 = vatnumber.substr(6,1)*3;
1283    var check8 = vatnumber.substr(7,1)*2;
1284
1285    var total= check1 + check2 + check3 + check4 + check5 + check6 + check7 + check8;
1286    var divisao= total / 11;
1287    var modulo11=total - parseInt(divisao)*11;
1288    if ( modulo11==1 || modulo11==0){ comparador=0; } // excepção
1289    else { comparador= 11-modulo11;}
1290
1291
1292    var ultimoDigito=vatnumber.substr(8,1)*1;
1293    if ( ultimoDigito != comparador ){ temErro=1;}
1294
1295    if( vatnumber.length < 9 ){ temErro=1; }
1296
1297    if( vatnumber == "999999990" ){ temErro=1; }
1298
1299    if (temErro==1){ return false; } else { return true; }
1300
1301    // CUSTOM
1302
1303  } else  {
1304    return false;
1305  }
1306}
1307
1308function ROVATCheckDigit (vatnumber) {
1309
1310  // Checks the check digits of a Romanian VAT number.
1311  
1312  var multipliers = [7,5,3,2,1,7,5,3,2];
1313  
1314  // Extract the next digit and multiply by the counter.
1315  var VATlen = vatnumber.length;
1316  multipliers = multipliers.slice (10-VATlen);
1317  var total = 0;
1318  for (var i = 0; i < vatnumber.length-1; i++) {
1319    total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1320  }  
1321  
1322  // Establish check digits by getting modulus 11.
1323  total = (10 * total) % 11;
1324  if (total == 10) total = 0; 
1325  
1326  // Compare it with the last character of the VAT number. If it is the same, then it's a valid 
1327  // check digit.
1328  if (total == vatnumber.slice (vatnumber.length-1, vatnumber.length))
1329    return true
1330  else 
1331    return false;
1332}
1333
1334function SEVATCheckDigit (vatnumber) {
1335
1336  // Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
1337  var R = 0;
1338  var digit;
1339  for (var i = 0; i < 9; i=i+2) {
1340    digit = Number(vatnumber.charAt(i));
1341    R = R + Math.floor(digit / 5)  + ((digit * 2) % 10);
1342  }
1343  
1344  // Calculate S where S = C2 + C4 + C6 + C8
1345  var S = 0;
1346  for (var i = 1; i < 9; i=i+2) S = S + Number(vatnumber.charAt(i));
1347  
1348  // Calculate the Check Digit
1349  var cd = (10 - (R + S) % 10) % 10;  
1350  
1351  // Compare it with the 10th character of the VAT number. If it is the same, then it's a valid 
1352  // check digit.
1353  if (cd == vatnumber.slice (9,10)) 
1354    return true
1355  else 
1356    return false;
1357}
1358
1359function SIVATCheckDigit (vatnumber) {
1360
1361  // Checks the check digits of a Slovenian VAT number.
1362  
1363  var total = 0; 
1364  var multipliers = [8,7,6,5,4,3,2];
1365  
1366  // Extract the next digit and multiply by the counter.
1367  for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1368  
1369  // Establish check digits using modulus 11
1370  total = 11 - total % 11;
1371  if (total == 10) {total = 0;};  
1372  
1373  // Compare the number with the last character of the VAT number. If it is the 
1374  // same, then it's a valid check digit.
1375  if (total != 11 && total == vatnumber.slice (7,8)) 
1376    return true
1377  else 
1378    return false;
1379}
1380
1381function SKVATCheckDigit (vatnumber) {
1382
1383  // Checks the check digits of a Slovakian VAT number.
1384  
1385  // Check that the modulus of the whole VAT nnumber is 0 - else error
1386  if (Number(vatnumber % 11) == 0) 
1387    return true
1388  else 
1389    return false;
1390}
1391
1392function UKVATCheckDigit (vatnumber) {
1393
1394  // Checks the check digits of a UK VAT number.
1395  
1396  var multipliers = [8,7,6,5,4,3,2];
1397  
1398  // Government departments
1399  if (vatnumber.substr(0,2) == 'GD') {
1400    if (vatnumber.substr(2,3) < 500) 
1401      return true 
1402    else 
1403      return false;
1404  }
1405  
1406  // Health authorities
1407  if (vatnumber.substr(0,2) == 'HA') {
1408    if (vatnumber.substr(2,3) > 499) 
1409      return true 
1410    else 
1411      return false;
1412  }
1413  
1414  // Standard and commercial numbers
1415  var total = 0;
1416  
1417  // 0 VAT numbers disallowed!
1418  if (Number(vatnumber.slice(0)) == 0) return false;
1419  
1420  // Check range is OK for modulus 97 calculation
1421  var no = Number(vatnumber.slice(0,7));
1422  
1423  // Extract the next digit and multiply by the counter.
1424  for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];
1425
1426  // Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our 
1427  // VAT number could use either system, so we check it against both.
1428
1429  // Establish check digits by subtracting 97 from total until negative.
1430  var cd = total;
1431  while (cd > 0) {cd = cd - 97;}    
1432
1433  // Get the absolute value and compare it with the last two characters of the VAT number. If the 
1434  // same, then it is a valid traditional check digit. However, even then the number must fit within
1435  // certain specified ranges.
1436  cd = Math.abs(cd);
1437  if (cd == vatnumber.slice (7,9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
1438  
1439  // Now try the new method by subtracting 55 from the check digit if we can - else add 42
1440  if (cd >= 55) 
1441    cd = cd - 55
1442  else
1443    cd = cd + 42;
1444  if (cd == vatnumber.slice (7,9) && no > 1000000) 
1445    return true;
1446  else
1447    return false; 
1448}

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.