Validates debit and credit cards numbers against regular expressions and Luhn algorithm for PHP 7.0+ Also validates the CVC and the expiration date. Project based on and inspired by inacho/php-credit-card-validator
Require the package in composer.json
"require": {
"samyan/bankcard-validator": "1.*"
},
Debit cards
- Visa Electron
- Maestro
- Forbrugsforeningen
- Dankort
Credit cards
- Visa
- Mastercard
- Amex
- Diners Club
- Discover
- UnionPay
- JCB (Japan Credit Bureau)
- Elo
- Hipercard
- Mir
- UATP (Universal Air Travel Plan)
- RuPay
$card = BankCard::validateCardNumber('5500005555555559', 'mastercard');
print_r($card);
Output:
Array
(
[valid] => 1
[number] => 5500005555555559
[type] => mastercard
)
$card = BankCard::validateCardNumber('371449635398431');
print_r($card);
Output:
Array
(
[valid] => 1
[number] => 371449635398431
[type] => amex
)
$validCvc = BankCard::isValidCvc('234', 'visa');
var_dump($validCvc);
Output:
bool(true)
$validDate = BankCard::isValidDate('2013', '07'); // past date
var_dump($validDate);
Output:
bool(false)