freelancehunt/php-credit-card-validator

Validates popular debit and credit cards' numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date.

Maintainers

πŸ‘ thedotedge

Package info

github.com/freelancehunt/php-credit-card-validator

pkg:composer/freelancehunt/php-credit-card-validator

Statistics

Installs: 678 373

Dependents: 2

Suggesters: 0

Stars: 18

Open Issues: 1

3.2.2 2021-01-16 08:13 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 1cf0b839c1ade1ac51302b21d17e59d796281282

  • Oleg Topchiy <edge.woop@freelancehunt.com>
  • Vitaliy Misko <vitaliy.woop@freelancehunt.com>
  • Yaroslav Molchan <yaroslav.woop@freelancehunt.com>
  • Ignacio de TomΓ‘s <nacho.woop@inacho.es>

validatorpaymentcardcreditdebitcreditcardcvc

This package is auto-updated.

Last update: 2026-06-16 20:20:21 UTC


README

πŸ‘ Build Status
πŸ‘ codecov
πŸ‘ PHP from Packagist
πŸ‘ Packagist
πŸ‘ Packagist
πŸ‘ License

Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date.

Since original project seems to be abandoned, we plan to maintain this fork.

Requirements

PHP 7.1+. We don't plan to support EOL PHP versions.

Require the package in composer.json

"require": {
 "freelancehunt/php-credit-card-validator": "3.*"
},

Usage

Validate a card number knowing the type:

$card = CreditCard::validCreditCard('5500005555555559', CreditCard::TYPE_MASTERCARD);
print_r($card);

Output:

Array
(
 [valid] => 1
 [number] => 5500005555555559
 [type] => mastercard
)

Validate a card number against several types:

$card = CreditCard::validCreditCard('5500005555555559', [CreditCard::TYPE_VISA, CreditCard::TYPE_MASTERCARD]);
print_r($card);

Output:

Array
(
 [valid] => 1
 [number] => 5500005555555559
 [type] => mastercard
)

Validate a card number and return the type:

$card = CreditCard::validCreditCard('371449635398431');
print_r($card);

Output:

Array
(
 [valid] => 1
 [number] => 371449635398431
 [type] => amex
)

Validate the CVC

$validCvc = CreditCard::validCvc('234', CreditCard::TYPE_VISA);
var_dump($validCvc);

Output:

bool(true)

Validate the expiration date

$validDate = CreditCard::validDate('2013', '07'); // past date
var_dump($validDate);

Output:

bool(false)

Tests

Execute the following command to run the unit tests:

vendor/bin/phpunit