/ Published in: PHP
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function fnValidateCc($mValue, $sCard = '')
{
if ($sCard == 'visa')
{
$sPattern = '/^4([0-9]{12}|[0-9]{15})$/';
}
else if ($sCard == 'amex')
{
$sPattern = '/^3[4|7][0-9]{13}$/';
}
else if ($sCard == 'mastercard')
{
$sPattern = '/^5[1-5][0-9]{14}$/';
}
else if ($sCard == 'discover')
{
$sPattern = '/^6011[0-9]{12}$/';
}
else if ($sCard == 'dinners')
{
$sPattern = '/^[30|36|38]{2}[0-9]{12}$/';
}
{
$sPattern = '/^[0-9]{13,19}$/';
}
else
{
return false;
}
{
// Modulo 10
$iSum = 0;
$iWeight = 2;
for ($i = $iLength - 2; $i >= 0; $i--)
{
$iDigit = $iWeight * $mValue[$i];
$iWeight = $iWeight % 2 + 1;
}
if ((10 - $iSum % 10) % 10 == $mValue[$iLength - 1])
{
return true;
}
}
return false;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                