Created
April 8, 2014 17:37
-
-
Save ecoreng/10160853 to your computer and use it in GitHub Desktop.
Credit card identification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CreditCardCompany($ccNum) | |
{ | |
/* | |
* 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 a prefix of 6011, and must be 16 digits in length. | |
* JCB: Must have a prefix of 3, 1800, or 2131, and must be either 15 or 16 digits in length. | |
*/ | |
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("^6011[0-9]{12}$", $ccNum)) | |
return "Discover"; | |
return 'Credit'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment