PHPackages                             horat1us/luhn-algorithm - 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. horat1us/luhn-algorithm

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

horat1us/luhn-algorithm
=======================

Implementation of the Luhn algorithm in PHP. Used in validation of credit card numbers and some national identification numbers.

6.0.0(11mo ago)0131MITPHPPHP ^7.4||^8.0CI passing

Since Jun 11Pushed 11mo agoCompare

[ Source](https://github.com/Horat1us/luhn-algorithm)[ Packagist](https://packagist.org/packages/horat1us/luhn-algorithm)[ RSS](/packages/horat1us-luhn-algorithm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (1)

Luhn Algorithm
==============

[](#luhn-algorithm)

[![PHP Tests & Lint](https://github.com/Horat1us/luhn-algorithm/actions/workflows/php.yml/badge.svg)](https://github.com/Horat1us/luhn-algorithm/actions/workflows/php.yml)

This is a zero dependency implementation of the Luhn Algorithm for PHP 7.4 and above. The Luhn Algorithm is used to validate things like credit cards and national identification numbers. More information on the algorithm can be found at [Wikipedia](http://en.wikipedia.org/wiki/Luhn_algorithm).

This is fork of [Ekman/luhn-algorithm](https://github.com/Ekman/luhn-algorithm) with PHP 8.4 compatibility fix.

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

[](#installation)

Install with [Composer](https://getcomposer.org/):

```
composer require horat1us/luhn-algorithm:^6.0
```

Usage
-----

[](#usage)

In order to instantiate a new instance of the library, use the factory:

```
use Nekman\LuhnAlgorithm\LuhnAlgorithmFactory;

$luhn = LuhnAlgorithmFactory::create();
```

You can find [the library facade in the `LuhnAlgorithmInterface.php` file](src/Contract/LuhnAlgorithmInterface.php).

[The `Number` class](src/Number.php) is a container class that holds the actual number and the check digit. It does no validation nor does it calculate the check digit. It exists to clearly separate the number from the check digit and to define when the check digit exists or not. To simplify the process of validating a number you can use the named constructor `Number::fromString()` like this:

```
use Nekman\LuhnAlgorithm\Number;

// Assume $creditCard is from a form.
$number = Number::fromString($creditCard);

if ($luhn->isValid($number)) {
    // Number is valid.
}
```

Alternatively, if you want to calculate the checksum or check digit for a number:

```
use Nekman\LuhnAlgorithm\Number;

$number = new Number(12345);

$checksum = $luhn->calcChecksum($number);

$checkDigit = $luhn->calcCheckDigit($number);
```

Versioning
----------

[](#versioning)

This project complies with [Semantic Versioning](https://semver.org/).

Changelog
---------

[](#changelog)

For a complete list of changes, and how to migrate between major versions, see [releases page](https://github.com/horat1us/luhn-algorithm/releases).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance52

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

341d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2751367?v=4)[Horat1us](/maintainers/Horat1us)[@Horat1us](https://github.com/Horat1us)

---

Top Contributors

[![lindyhopchris](https://avatars.githubusercontent.com/u/4464333?v=4)](https://github.com/lindyhopchris "lindyhopchris (1 commits)")[![p16](https://avatars.githubusercontent.com/u/272483?v=4)](https://github.com/p16 "p16 (1 commits)")[![vanodevium](https://avatars.githubusercontent.com/u/16780069?v=4)](https://github.com/vanodevium "vanodevium (1 commits)")

---

Tags

validationcardidentificationluhncredit

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/horat1us-luhn-algorithm/health.svg)

```
[![Health](https://phpackages.com/badges/horat1us-luhn-algorithm/health.svg)](https://phpackages.com/packages/horat1us-luhn-algorithm)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M672](/packages/composer-semver)[nekman/luhn-algorithm

Implementation of the Luhn algorithm in PHP. Used in validation of credit card numbers and some national identification numbers.

22819.4k](/packages/nekman-luhn-algorithm)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)

PHPackages © 2026

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