nekman/luhn-algorithm

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

3.0.0 2018-02-19 15:13 UTC

README

Build Status

This is an implementation of the Luhn Algorithm in PHP. The Luhn Algorithm is used to validate things like credit cards and national identifcation numbers. More information on the algorithm can be found at Wikipedia

Installation

Can be installed using composer:

composer require nekman/luhn-algorithm

Usage

Use the class like this:

use Nekman\LuhnAlgorithm\LuhnAlgorithmFactory;

$luhn = LuhnAlgorithmFactory::create();

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

$checkSum = $luhn->calcCheckSum(123456789);

$checkDigit = $luhn->calcCheckDigit(123456789);

Changelog

  • 4.0.0 - Rewrite of the implementation.
  • 3.0.0 - Completely restructured the interface of the library.
  • 2.0.1 - Fixed typos in interface.
  • 2.0.0 - Added namespace.
  • 1.0.0 - Initial release.