PHP code example of jlorente / php-credit-cards

1. Go to this page and download the library: Download jlorente/php-credit-cards library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jlorente / php-credit-cards example snippets


$validator = new CreditCardValidator();

$validator = CreditCardValidator::make();

$validator = new CreditCardValidator([
    CreditCardValidator::TYPE_VISA,
    CreditCardValidator::TYPE_MASTERCARD,
]);

$validator = CreditCardValidator::make([
    CreditCardValidator::TYPE_VISA,
    CreditCardValidator::TYPE_MASTERCARD,
]);

$validator->isValid('4242424242424242');

$validator->is(CreditCardValidator::TYPE_VISA, '4242424242424242');

$validator->isVisa('4242424242424242');

$typeConfig = $validator->getType('4242424242424242');

[
    'example-card' => [
        'niceType' => 'Test Card',    // Display name
        'type' => 'example-card',     // Type/Code name
        'patterns' => [               // Valid patterns for the card
            272012,                   // Simple validator: true if the card begins with the pattern 272012
            [5, 89],                  // Range validator: true if the card initial two digits value is between 5 and 89 both ' => [                   // Security code configuration
            'name' => 'CVV',          // Name of the security code
            'size' => 3,              // Valid length of the security code
        ],
        'luhnCheck' => true           // To validate the Luhn's algorithm when calling matches
    ],
];
bash
$ php composer.phar 
json
...
    "rente/php-credit-cards": "*"
    }