Check if card is VISA or VISAElectron

This question already has an answer here:

  • How do you detect Credit card type based on number? 26 answers

  • 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" => "(4d{12}(?:d{3})?)",
        "amex" => "(3[47]d{13})",
        "jcb" => "(35[2-8][89]ddd{10})",
        "maestro" => "((?:5020|5038|6304|6579|6761)d{12}(?:dd)?)",
        "solo" => "((?:6334|6767)d{12}(?:dd)?d?)",
        "mastercard" => "(5[1-5]d{14})",
        "switch" => "(?:(?:(?:4903|4905|4911|4936|6333|6759)d{12})|(?:(?:564182|633110)d{10})(dd)?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

    链接地址: http://www.djcxy.com/p/70704.html

    上一篇: 正则表达式发现信用卡

    下一篇: 检查卡是VISA还是VISAElectron