Skip to content

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 project based on and inspired by inacho/php-credit-card-validator

Notifications You must be signed in to change notification settings

samyan/bankcard-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP Bank Card Validator

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)

About

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 project based on and inspired by inacho/php-credit-card-validator

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages