PHPackages                             designbycode/credit-card-validator - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. designbycode/credit-card-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

designbycode/credit-card-validator
==================================

The Credit Card Validator package provides a set of classes to validate credit card numbers, expiry dates, and CVV codes. This package is designed to help you ensure that the credit card information provided by users is valid and accurate.

v1.0.2(1y ago)111[1 PRs](https://github.com/designbycode/credit-card-validator/pulls)MITPHPPHP ^8.1|^8.2|^8.3

Since Jun 29Pushed 1y agoCompare

[ Source](https://github.com/designbycode/credit-card-validator)[ Packagist](https://packagist.org/packages/designbycode/credit-card-validator)[ Docs](https://github.com/designbycode/credit-card-validator)[ GitHub Sponsors](https://github.com/designbycode)[ RSS](/packages/designbycode-credit-card-validator/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (4)Versions (5)Used By (0)

Credit card validator
=====================

[](#credit-card-validator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/59090e1efda6dbfb13cb4f727aa72f2d89d00ab4c232a8e1ab5f6e89c2fe25e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657369676e6279636f64652f6372656469742d636172642d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/designbycode/credit-card-validator)[![Tests](https://camo.githubusercontent.com/6d46760d1864ea83c8b393bf0f17143dd38793b1f63dff2735c53dd1f9a6850f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64657369676e6279636f64652f6372656469742d636172642d76616c696461746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/designbycode/credit-card-validator/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/513a7a39296990fcdaf1c92506530f42cdbd5b35bd42b1f42224377501e4631a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657369676e6279636f64652f6372656469742d636172642d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/designbycode/credit-card-validator)

Introduction
------------

[](#introduction)

The Credit Card Validator package provides a set of classes to validate credit card numbers, expiry dates, and CVV codes. This package is designed to help you ensure that the credit card information provided by users is valid and accurate.

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

[](#installation)

You can install the package via composer:

```
composer require designbycode/credit-card-validator
```

Usage
-----

[](#usage)

### CreditCardValidator

[](#creditcardvalidator)

The `CreditCardValidator` class validates a credit card number.

#### Constructor

[](#constructor)

`__construct(string $cardNumber)`

`$cardNumber`: The credit card number to validate.

#### Methods

[](#methods)

- `isValid()`: bool: Returns true if the credit card number is valid, false otherwise.
- `getCardType()`: ?string: Returns the card type (amex, diners, visa, mastercard, discover, or null if unknown).

```
$card = new CreditCardValidator('4111 1111 1111 1111');
if ($card->isValid()) {
    echo 'Credit card number is valid';
} else {
    echo 'Credit card number is invalid';
}
```

### ExpiryDateValidator

[](#expirydatevalidator)

The `ExpiryDateValidator` class validates the expiry date of a credit card.

#### Constructor

[](#constructor-1)

`__construct(int $expiryMonth, int $expiryYear)`

- $expiryMonth: The expiry month (1-12).
- $expiryYear: The expiry year (YYYY).

#### Methods

[](#methods-1)

- `isValid()`: bool: Returns true if the expiry date is valid, false otherwise.

```
$validator = new ExpiryDateValidator(12, 2025);
if ($validator->isValid()) {
    echo 'Expiry date is valid';
} else {
    echo 'Expiry date is invalid';
}
```

### CvvValidator

[](#cvvvalidator)

The `CvvValidator` class validates a CVV (Card Verification Value) code.

#### Constructor

[](#constructor-2)

`__construct(string $cvv, string $cardType)`

- $cvv: The CVV code to validate.
- $cardType: The card type (amex, visa, mastercard, etc.).

#### Methods

[](#methods-2)

- `isValid()`: bool: Returns true if the CVV code is valid, false otherwise.

```
$validator = new CvvValidator('123', 'visa');
or
$card = new CreditCardValidator('4111 1111 1111 1111')
$validator = new CvvValidator('123', $card->getCardType());

if ($validator->isValid()) {
    echo 'CVV code is valid';
} else {
    echo 'CVV code is invalid';
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Claude Myburgh](https://github.com/claudemyburgh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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

Every ~10 days

Total

3

Last Release

712d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6057076?v=4)[Claude Myburgh](/maintainers/claudemyburgh)[@claudemyburgh](https://github.com/claudemyburgh)

---

Top Contributors

[![claudemyburgh](https://avatars.githubusercontent.com/u/6057076?v=4)](https://github.com/claudemyburgh "claudemyburgh (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

credit-carddesignbycodecredit-card-validator

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/designbycode-credit-card-validator/health.svg)

```
[![Health](https://phpackages.com/badges/designbycode-credit-card-validator/health.svg)](https://phpackages.com/packages/designbycode-credit-card-validator)
```

###  Alternatives

[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2462.4M7](/packages/laravel-validation-rules-credit-card)[rap2hpoutre/laravel-credit-card-validator

Laravel credit card validator

22130.9k](/packages/rap2hpoutre-laravel-credit-card-validator)[dragon-code/card-number

Generation and verification of card numbers using Luhn's algorithm.

6613.6k](/packages/dragon-code-card-number)

PHPackages © 2026

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