phool4fool
203.***.***.***
Credit Card Number Validation
this function takes a string of the cardnumber with no blanks, and returns true if the number validates as a creditcard number, else it returns false.
PHP Example:
function validate_cardnum($cardnum)
{
$checkdigit=substr($cardnum,-1);
$remainingcardnum=substr($cardnum,0,strlen($cardnum)-1);
$i=0;
while($i < strlen($remainingcardnum))
{
if($i%2==0)
$remaing_array[$i]=substr($remainingcardnum,($i+1)*-1,1) * 2;
else
$remaing_array[$i]=substr($remainingcardnum,($i+1)*-1,1);
if($remaing_array[$i]>=10)
$checksum=$checksum+1;
$checksum=$checksum+($remaing_array[$i]%10);
$i++;
}
$calculatedcheckdigit=(10-($checksum%10))%10;
if( $calculatedcheckdigit==$checkdigit)
return true;
else
return false;
}
This is excellent. I actually have use for this as a pre-screen on a sales site I am contracted on. Thanks for sharing the code. Do all cards use the same formula for validation?
triumph;305:
This is excellent. I actually have use for this as a pre-screen on a sales site I am contracted on. Thanks for sharing the code. Do all cards use the same formula for validation?
I think this formula will aplly to all credit cards and we can say it some universal type of coding to handle all cards .is not it?
penguinmama
12.***.***.***
I'm curious how this works. It appears to just make sure they are all numeric and enough of them? But the ones I've seen *used* seem to check deeper than that - to see if the first four digits are a valid card starter, I think...
What exactly does the code above *do*?
i need to know ho do i get the knowledge that my creditcard has been vilidated?
How do u validated the whether the card is fake or not even if its number matched with credit card
Nice less of a chance of fraud. I'm gonna play with this script =]
@Michael: this only looks and see if the fields are filled in. This is just a snippet, you must have a bigger script or something to record the numbers to a secure database. So you can check them later with a machine or a site like PayPal to get your payment. It will tell you if it's really been "validated"
@mtajim: You don't until you charge the card.
i believe the first 4 numbers correlate to the respective CC company.