samyan / bankcard-validator
php bankcard validator
Installs: 1 136
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
README
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
Installation
Require the package in composer.json
"require": { "samyan/bankcard-validator": "1.*" },
Actual supported Bank Cards
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
Usage
Validate a card number knowing the type:
$card = BankCard::validateCardNumber('5500005555555559', 'mastercard'); print_r($card);
Output:
Array
(
[valid] => 1
[number] => 5500005555555559
[type] => mastercard
)
Validate a card number and return the type:
$card = BankCard::validateCardNumber('371449635398431'); print_r($card);
Output:
Array
(
[valid] => 1
[number] => 371449635398431
[type] => amex
)
Validate the CVC
$validCvc = BankCard::isValidCvc('234', 'visa'); var_dump($validCvc);
Output:
bool(true)
Validate the expiration date
$validDate = BankCard::isValidDate('2013', '07'); // past date var_dump($validDate);
Output:
bool(false)