Skip to content

Instantly share code, notes, and snippets.

@muhittin
Created February 12, 2013 15:03
Show Gist options
  • Save muhittin/4770453 to your computer and use it in GitHub Desktop.
Save muhittin/4770453 to your computer and use it in GitHub Desktop.
MasterCard: Must have a prefix of 51 to 55, and must be 16 digits in length. Visa: Must have a prefix of 4, and must be either 13 or 16 digits in length. American Express: Must have a prefix of 34 or 37, and must be 15 digits in length. Diners Club: Must have a prefix of 300 to 305, 36, or 38, and must be 14 digits in length. Discover: Must have…
function credit_card_type($ccNum)
{
if (ereg("^5[1-5][0-9]{14}$", $ccNum))
return "Mastercard";
if (ereg("^4[0-9]{12}([0-9]{3})?$", $ccNum))
return "Visa";
if (ereg("^3[47][0-9]{13}$", $ccNum))
return "American Express";
if (ereg("^3(0[0-5]|[68][0-9])[0-9]{11}$", $ccNum))
return "Diners Club";
if (ereg("^6011[0-9]{12}$", $ccNum))
return "Discover";
if (ereg("^(3[0-9]{4}|2131|1800)[0-9]{11}$", $ccNum))
return "JCB";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment