WannaLearn
Programmer
Code:
function cccheck (formobj, type, no)
{
for(i = 0; i < formobj.elements[type].length; i++)
{
var cctype="";
if(formobj.elements[type][i].checked)
{
cctype = formobj.elements[type][i].value;
break;
}
}
if(cctype=="")
{
alert ("Please select a credit card!");
return false;
}
var ccno=formobj.elements[no].value;
//check number of digits
if(
!(
(cctype == 'Mastercard' && ccno.length == 16) ||
(cctype == 'Visa' && (ccno.length == 13 || ccno.length == 16)) ||
(cctype == 'Amex' && ccno.length == 15) ||
(cctype == 'Discover' && ccno.length == 16)
)
)
{
alert ("Invalid credit card number length!");
return false;
}
var sum = 0;
for (i = 0; i < ccno.length; i++)
{
var intval = parseInt(ccno.charAt(ccno.length-i-1));
if(isNaN(intval))
{
alert ("Invalid credit card number!");
return false;
}
if ((i%2) != 0) intval = intval*2;
sum = sum + intval%10;
if (intval > 9) sum = sum + 1;
}
var modno = sum%10;
if (modno != 0)
{
alert ("Invalid credit card number!");
return false;
}
else
return true;
}
I was just wondering. We use that here and I just wanted to know. Thanks a lot.