LaravelPackages.net
Acme Inc.
Toggle sidebar
convenia/credit-card-validator-php

Fork Off inacho/php-credit-card-validator Because it looks like is not being manteined anymore --- Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date

51.309
1
1.1.0
About convenia/credit-card-validator-php

convenia/credit-card-validator-php is a Laravel package for fork off inacho/php-credit-card-validator because it looks like is not being manteined anymore --- validates popular debit and credit cards numbers against regular expressions and luhn algorithm. also validates the cvc and the expiration date. It currently has 1 GitHub stars and 51.309 downloads on Packagist (latest version 1.1.0). Install it with composer require convenia/credit-card-validator-php. Discover more Laravel packages by convenia or browse all Laravel packages to compare alternatives.

Last updated

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.

This package is a Fork of inacho/php-credit-card-validator because it looks like isn't manteined anymore

Installation

Require the package in composer.json

"require": {
    "convenia/credit-card-validator-php": "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

Star History Chart