first i want to tell that i wrote as you the problem without trying and i wait for the answer but anyone send me a reply, for that i learn to search the algorithm from the internet , so what i wrote below is just what i found in my search; if it is not enough you could search further, good luck ;-)
// Run through each single digit to create a new string. Even digits
// are multiplied by two, odd digits are left alone.
t = " ";
for (i = 0; i < r.length; i++) {
c = parseInt(r.charAt(i), 10);
if (i % 2 != 0)
c *= 2;
t = t + c;
}
// Finally, add up all the single digits in this string.
n = 0;
for (i = 0; i < t.length; i++) {
c = parseInt(t.charAt(i), 10);
n = n + c;
}
Once the sum is found, the code checks to see if it's an even multiple of ten (i.e., n % 10 leaves no remainder).
// If the resulting sum is an even multiple of ten (but not zero), the
// card number is good.
if (n != 0 && n % 10 == 0)
return true;
else
return false;
}