inacho/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
1,456,617 209
Install
composer require inacho/php-credit-card-validator
Latest Version:1.0.2
PHP:>=5.3.0
License:MIT
Last Updated:Aug 22, 2023
Links: GitHub  ·  Packagist
Maintainer: inacho

PHP Credit Card Validator

Build Status Coverage Status Latest Stable Version Total Downloads

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

Installation

Require the package in composer.json

"require": {
    "inacho/php-credit-card-validator": "1.*"
},

If you are using Laravel, add an alias in config/app.php

'aliases' => array(

    'App'             => 'Illuminate\Support\Facades\App',
    ...
    'View'            => 'Illuminate\Support\Facades\View',

    'CreditCard'      => 'Inacho\CreditCard',

),

Usage

Validate a card number knowing the type:

$card = CreditCard::validCreditCard('5500005555555559', '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', '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

Related Packages

annaghd/php-credit-card-validator-plus

Validates popular debit and credit cards numbers against regular expressions and...

13,626 1
jlorente/laravel-credit-cards

Laravel >=5.6 integration for the PHP Credit Cards package that allows to perfor...

39,558 7
illuminatech/balance

Provides support for Balance accounting system based on debit and credit princip...

49,300 163
dartui/polish-validators

Polish Validators for Laravel

1,574 4
gzero/validator

Gzero CMS Validator

957 1

Version History

Version Released PHP License
1.0.2 >=5.3.0 MIT
1.0.1 >=5.3.0 MIT
1.0.0 >=5.3.0 MIT