SHARE
TWEET

Untitled

a guest Dec 14th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unction mod10_check(val){
  2.  
  3.     var nondigits = new RegExp(/[^0-9]+/g);
  4.  
  5.     var number = val.replace(nondigits,'');
  6.  
  7.     var pos, digit, i, sub_total, sum = 0;
  8.  
  9.     var strlen = number.length;
  10.  
  11.     if(strlen < 13){ return false; }
  12.  
  13.     for(i=0;i<strlen;i++){
  14.  
  15.         pos = strlen - i;
  16.  
  17.         digit = parseInt(number.substring(pos - 1, pos));
  18.  
  19.         if(i % 2 == 1){
  20.  
  21.             sub_total = digit * 2;
  22.  
  23.             if(sub_total > 9){
  24.  
  25.                 sub_total = 1 + (sub_total - 10);
  26.  
  27.             }
  28.  
  29.         } else {
  30.  
  31.             sub_total = digit;
  32.  
  33.         }
  34.  
  35.         sum += sub_total;
  36.  
  37.     }
  38.  
  39.     if(sum > 0 && sum % 10 == 0){
  40.  
  41.         return true;
  42.  
  43.     }
  44.  
  45.     return false;
  46.  
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top