Formula pada bilangan kartu kredit

Kartu kredit adalah sistem pembayaran di mana penerbit (issuer) kartu meminjamkan uang kepada pelanggan (cardholder) untuk dibayarkan ke penerima pembayaran transaksi dengan kartu kredit (merchant). Sebuah kartu kredit berbeda dari kartu debit, karena kartu kredit tidak menghapus/mengurangi uang dari rekening pelanggan setelah transaksi. Hampir semua kartu kredit memiliki bentuk dan ukuran yang sama, sesuai dengan spesifikasi standar ISO 7810.

Formula di Excel :

=IF(RIGHT(B6,1)*1=IF(MOD(IF(LEFT(B6,1)*2>9,(LEFT(B6,1)*2)-9,LEFT(B6,1)*2)+IF(MID(B6,3,1)*2>9,(MID(B6,3,1)*2)-9,MID(B6,3,1)*2)+IF(MID(B6,5,1)*2>9,(MID(B6,5,1)*2)-9,MID(B6,5,1)*2)+IF(MID(B6,7,1)*2>9,(MID(B6,7,1)*2)-9,MID(B6,7,1)*2)+IF(MID(B6,9,1)*2>9,(MID(B6,9,1)*2)-9,MID(B6,9,1)*2)+IF(MID(B6,11,1)*2>9,(MID(B6,11,1)*2)-9,MID(B6,11,1)*2)+IF(MID(B6,13,1)*2>9,(MID(B6,13,1)*2)-9,MID(B6,13,1)*2)+MID(B6,2,1)+MID(B6,4,1)+MID(B6,6,1)+MID(B6,8,1)+MID(B6,10,1)+MID(B6,12,1)+MID(B6,14,1),10)=0,0,(10-MOD(IF(LEFT(B6,1)*2>9,(LEFT(B6,1)*2)-9,LEFT(B6,1)*2)+IF(MID(B6,3,1)*2>9,(MID(B6,3,1)*2)-9,MID(B6,3,1)*2)+IF(MID(B6,5,1)*2>9,(MID(B6,5,1)*2)-9,MID(B6,5,1)*2)+IF(MID(B6,7,1)*2>9,(MID(B6,7,1)*2)-9,MID(B6,7,1)*2)+IF(MID(B6,9,1)*2>9,(MID(B6,9,1)*2)-9,MID(B6,9,1)*2)+IF(MID(B6,11,1)*2>9,(MID(B6,11,1)*2)-9,MID(B6,11,1)*2)+IF(MID(B6,13,1)*2>9,(MID(B6,13,1)*2)-9,MID(B6,13,1)*2)+MID(B6,2,1)+MID(B6,4,1)+MID(B6,6,1)+MID(B6,8,1)+MID(B6,10,1)+MID(B6,12,1)+MID(B6,14,1),10))),"VALID","TIDAK VALID")

 

C#

int[] CreateNumber(int length)
 {
   Random random = new Random();
   int[] digits = new int[length];
   // For loop keeps default value of zero for
last slot in array
   for(int i = 0; i < length - 1; i++)
   {
     digits[i] = random.Next(10);
   }
   int sum = 0;
   bool alt = true;
   for(int i = length - 2; i >= 0; i--)
   {
     if(alt)
     {
       int temp = digits[i];
       temp *= 2;
       if(temp > 9)
       {
         temp -= 9;
       }
       sum += temp;
     }
     else
     {
       sum += digits[i];
     }
     alt = !alt;
   }
   int modulo = sum % 10;
   if(modulo > 0)
   {
     digits[length-1] = 10 - modulo;
   }
   // No else req'd - keep default value of
zero for digits[length-1]
   return digits;
 }

 

Java

<!--
function Mod10(ccNumb) { //v2.0
var valid 	= "0123456789"
var len 	= ccNumb.length;
var bNum 	= true;
var iCCN 	= ccNumb;
var sCCN 	= ccNumb.toString();
var iCCN;
var iTotal 	= 0;
var bResult = false;
var digit;
var temp;
	iCCN = sCCN.replace (/^\s+|\s+$/g,'');	// strip spaces
    //alert(iCCN);
for (var j=0; j<len; j++) {
temp = "" + iCCN.substring(j, j+1);
if (valid.indexOf(temp) == "-1") bNum = false;
}
if(!bNum){alert("Not a Number");}
    iCCN = parseInt(iCCN);

if(len == 0){ /* nothing, field is blank */
	bResult = true;
}else{
	if(len >= 15){		//15 or 16 for Amex or V/MC
		for(var i=len;i>0;i--){
		digit = "digit" + i;
		//alert(digit);

			calc = parseInt(iCCN) % 10;	//right most digit
			calc = parseInt(calc);
			//alert(calc);
			iTotal += calc;		//parseInt(cardnum.charAt(count))i:\t" + calc.toString() + " x 2 = " + (calc *2) +" : " + calc2 + "\n";
			// commented out below which wrote NONALTERED digit to page for demo only.
			//document.form1.textfield.value += "" + i + ":\t" + calc.toString() + " x 1 = " + calc + "\n";

			i--;
		digit = "digit" + i;
		//alert(digit);

			iCCN = iCCN / 10; 	// subtracts right most digit from ccNum
			calc = parseInt(iCCN) % 10 ;	// step 1 double every other digit
			 //alert( iCCN + " " + calc);
			 calc2 = calc *2;

			switch(calc2){
				case 10: calc2 = 1; break;	//5*2=10 & 1+0 = 1
				case 12: calc2 = 3; break;	//6*2=12 & 1+2 = 3
				case 14: calc2 = 5; break;	//7*2=14 & 1+4 = 5
				case 16: calc2 = 7; break;	//8*2=16 & 1+6 = 7
				case 18: calc2 = 9; break;	//9*2=18 & 1+8 = 9
				default: calc2 = calc2; 		//4*2= 8 &   8 = 8  -same for all lower numbers
			}
			iCCN = iCCN / 10; 	// subtracts right most digit from ccNum
			iTotal += calc2;
			// commented out below which wrote MULTIPLIED digit to page for demo only
			//document.form1.textfield.value += "" + i +":\t" + calc.toString() + " x 2 = " + (calc *2) +" : " + calc2 + "\n";
		}
			// commeneted out SUM below for demo only
			//document.form1.textfield.value += "\t\tSum: " + iTotal + "\n";
		if ((iTotal%10)==0){
			//document.calculator.results.value = "Yes";
			bResult = true;
 		}else{
			//document.calculator.results.value = "No";
			bResult = false;
		}
	}
}
// change alert to on-page display or other indication if needed.
if(!bResult){alert("This is NOT a valid Credit Card Number!");}
  return false;
}
//-->
Iklan

Good People write good comments ..

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s