samyan/bankcard-validator

php bankcard validator

1.1 2020-12-04 14:40 UTC

This package is auto-updated.

Last update: 2024-10-19 19:27:13 UTC


README

Latest Stable Version Total Downloads License

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)