2

How can i check if the creditcard is VISA Debit or Visa Electron? I found this example, but i don't know anything about creditcard algortime.

I know how the functions works, i am just asking how i can check if it's a VISA ELECTRON or VISA DEBIT card. Currently it only supports VISA Debits, but it need to make a check for VISA ELECTRON

$cards = array(
    "visa" => "(4\d{12}(?:\d{3})?)",
    "visaelectron" => "??????????????????????????",
    "amex" => "(3[47]\d{13})",
    "jcb" => "(35[2-8][89]\d\d\d{10})",
    "maestro" => "((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)",
    "solo" => "((?:6334|6767)\d{12}(?:\d\d)?\d?)",
    "mastercard" => "(5[1-5]\d{14})",
    "switch" => "(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)",
);

Thanks!

  • Look at this question : http://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number – BMN Mar 03 '14 at 11:26
  • if you "don't know anything about creditcard algoritme", you should research it. We expect you to do your homework before asking questions. All you are now telling us is "i found this code. i have no clue what it does. fix it for me" – Gordon Mar 03 '14 at 11:28
  • I know how it works, please see post again. Sorry – Jesper Kampmann Madsen Mar 03 '14 at 11:31

1 Answers1

1

The array you've found contains regular expressions.

You could loop through this array and check if the value provided matches one of the regular expressions, and if so, you know what type of card they have used.

Something like this:

$cards = array(
    "visa" => "(4\d{12}(?:\d{3})?)",
    "amex" => "(3[47]\d{13})",
    "jcb" => "(35[2-8][89]\d\d\d{10})",
    "maestro" => "((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)",
    "solo" => "((?:6334|6767)\d{12}(?:\d\d)?\d?)",
    "mastercard" => "(5[1-5]\d{14})",
    "switch" => "(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)",
);

$card_number = '4242424242424242'; // some made up card number

$card_type = 'unknown';

foreach ($cards as $card => $pattern) {
    if (preg_match('/' . $pattern . '/', $card_number)) {
        $card_type = $card;
        break;
    }
}

echo $card_type;

[EDIT] Now concerning your new requirement of 'visaelectron' matching.

Visa usually start with 49,44 or 47 Visa electron : 42,45,48,49

So you'll need to create a regular expression based on those rules and add it to your array

duellsy
  • 8,497
  • 2
  • 36
  • 60