Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Credit Card Validator

Script for the validation of credit cards.



<?php
function CCVal($Num, $Name = 'n/a') {
$GoodCard = true;
$Num = ereg_replace("[^[:digit:]]", "", $Num);
switch ($Name) {
case "mcd" :
    $GoodCard = ereg("^5[1-5].{14}$", $Num);
    break;
case "vis" :
    $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
    break;
case "amx" :
    $GoodCard = ereg("^3[47].{13}$", $Num);
    break;
case "dsc" :
    $GoodCard = ereg("^6011.{12}$", $Num);
    break;
case "dnc" :
    $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
    break;
case "jcb" :
    $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
    break;
}
$Num = strrev($Num);
$Total = 0;
for ($x=0; $x<strlen($Num); $x++) {
    $digit = substr($Num,$x,1);
    if ($x/2 != floor($x/2)) {
        $digit *= 2;
        if (strlen($digit) == 2)
            $digit = substr($digit,0,1) + substr($digit,1,1);
        }
        $Total += $digit;
    }
    if ($GoodCard && $Total % 10 == 0) return true; else return false;
}
?>


Download code...


Print this page


 

Inizio pagina

risorse per webmaster