PHPackages                             lloople/php-credit-cards - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lloople/php-credit-cards

ActiveLibrary

lloople/php-credit-cards
========================

A PHP package to perform operations on debit and credit cards like format, validate brand, number and Luhn algorithm. It validates popular brands like Visa, Mastercard, American Express, etc.

1.0.0(1y ago)06MITPHPPHP &gt;=5.4

Since Oct 2Pushed 1y agoCompare

[ Source](https://github.com/Lloople/php-credit-cards)[ Packagist](https://packagist.org/packages/lloople/php-credit-cards)[ RSS](/packages/lloople-php-credit-cards/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

PHP Credit Cards
================

[](#php-credit-cards)

A PHP package to perform operations on debit and credit cards like format, validate brand, number and Luhn algorithm. It validates popular brands like Visa, Mastercard, American Express, etc.

This package is based on the [braintree/credit-card-type](https://github.com/braintree/credit-card-type)javascript package. All the card types configuration have been extracted from it.

Current Cart Type Validators
----------------------------

[](#current-cart-type-validators)

- Visa
- Mastercard
- American Express
- Diners Club
- Discover
- JCB
- UnionPay
- Maestro
- Elo
- Mir
- Hiper
- Hipercard
- Troy
- Cabal

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

With Composer installed, you can then install the extension using the following commands:

```
$ php composer.phar require jlorente/php-credit-cards
```

or add

```
...
    "require": {
        "jlorente/php-credit-cards": "*"
    }
```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

You can create an instance of the validator either by using the common constructor or the static make method.

```
$validator = new CreditCardValidator();
```

or

```
$validator = CreditCardValidator::make();
```

By default, the validator will load the configuration of all the card types that come along with the package, but you can limit the allowed types by providing an array with the card type codes.

```
$validator = new CreditCardValidator([
    CreditCardValidator::TYPE_VISA,
    CreditCardValidator::TYPE_MASTERCARD,
]);
```

or

```
$validator = CreditCardValidator::make([
    CreditCardValidator::TYPE_VISA,
    CreditCardValidator::TYPE_MASTERCARD,
]);
```

### Validating a credit card number without knowing the type

[](#validating-a-credit-card-number-without-knowing-the-type)

```
$validator->isValid('4242424242424242');
```

### Validating a credit card number knowing the type

[](#validating-a-credit-card-number-knowing-the-type)

```
$validator->is(CreditCardValidator::TYPE_VISA, '4242424242424242');
```

or

```
$validator->isVisa('4242424242424242');
```

### Get the type configuration of a card number

[](#get-the-type-configuration-of-a-card-number)

```
$typeConfig = $validator->getType('4242424242424242');
```

With the type configuration you can know metadata info, perform some validation or format the card number using the class methods.

#### CreditCardTypeConfig

[](#creditcardtypeconfig)

MethodDescriptionReturn examplegetType(): stringGet the type of the card type configuration"visa", "mastercard"getNiceType(): stringGet the nice type of the card type configuration"Visa", "Mastercard"getPatterns(): arrayGet the patterns that the card type configuration uses to validate a card number\[50, \[55, 59\]\]getGaps(): arrayGet the index of the position in card number string where to put blank spaces on card formatting\[4, 8, 12\]getLengths(): arrayGet the allowed lengths that the card type configuration uses to validate the card numbers\[16, 19\]getCode(): stringGet the security code configuration of the card type\["name" =&gt; "CVC", "size" =&gt; 4\]getLuhnCheck(): boolGet the luhn check value of the configurationtruesetLuhnCheck(bool $value): $thisSet the luhn check value. If true, the validator will validate the card number with the Luhn's algorithmmatches(string $cardNumber): boolCheck if the given card number matches the card type configurationfalsematchesPatterns(string $cardNumber): boolCheck if the card number matches one of the patterns array configurationtruematchesLengths(string $cardNumber): boolCheck if the card number matches one of the lengths array configurationtruesatisfiesLuhn(string $cardNumber): boolCheck if the card number satisfies the luhn's algorithmtruematchesSecurityCode(string $cardNumber): boolCheck if the card number satisfies the luhn's algorithmfalseformat(string $cardNumber): stringFormat the card number according to the gap configuration"4242 4242 4242 4242"Contribute
----------

[](#contribute)

Feel free to add new credit card configurations or fix the current ones and create a pull request to keep the package up to date.

A credit type configuration has the following structure:

```
[
    'example-card' => [
        'niceType' => 'Test Card',    // Display name
        'type' => 'example-card',     // Type/Code name
        'patterns' => [               // Valid patterns for the card
            272012,                   // Simple validator: true if the card begins with the pattern 272012
            [5, 89],                  // Range validator: true if the card initial two digits value is between 5 and 89 both included
        ],
        'gaps' => [4, 10],            // Values where to put white spaces on pretty card formatting. In this example: XXXX XXXXXX XXXXXX
        'lengths' => [                // Valid lengths for the card
            15,                       // Simple validator: True if length is exactly 15
            [17, 19],                 // Range validator: True if length is between 17 and 19 both included
        ],
        'code' => [                   // Security code configuration
            'name' => 'CVV',          // Name of the security code
            'size' => 3,              // Valid length of the security code
        ],
        'luhnCheck' => true           // To validate the Luhn's algorithm when calling matches
    ],
];
```

License
-------

[](#license)

Copyright © 2020 José Lorente Martín .

Licensed under the MIT License. See LICENSE.txt for details.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

594d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/777a92668f51536d86a9fed19c92180d626b46f134b002c3a068e92d295c7541?d=identicon)[lloople](/maintainers/lloople)

---

Top Contributors

[![jlorente](https://avatars.githubusercontent.com/u/301741?v=4)](https://github.com/jlorente "jlorente (12 commits)")[![Lloople](https://avatars.githubusercontent.com/u/5665466?v=4)](https://github.com/Lloople "Lloople (6 commits)")[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (1 commits)")[![nuryagdym](https://avatars.githubusercontent.com/u/26792980?v=4)](https://github.com/nuryagdym "nuryagdym (1 commits)")

---

Tags

phpvalidatediscovercreditcardcardunionpayvisamastercarddebitcardsamerican expresscreditcardsjlorentediners clubtroy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lloople-php-credit-cards/health.svg)

```
[![Health](https://phpackages.com/badges/lloople-php-credit-cards/health.svg)](https://phpackages.com/packages/lloople-php-credit-cards)
```

###  Alternatives

[jlorente/php-credit-cards

A PHP package to perform operations on debit and credit cards like format, validate brand, number and Luhn algorithm. It validates popular brands like Visa, Mastercard, American Express, etc.

44421.2k1](/packages/jlorente-php-credit-cards)[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

2051.4M11](/packages/inacho-php-credit-card-validator)[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.

18620.4k2](/packages/freelancehunt-php-credit-card-validator)[skrepr/teams-connector

A simple PHP package for sending messages to Microsoft Teams

239.6k1](/packages/skrepr-teams-connector)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
