nekman/luhn-algorithm

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

Installs: 315

Dependents: 0

Stars: 3

Watchers: 1

Forks: 1

Open Issues: 1

Language: PHP

2.0.0 2014-06-01 15:47 UTC

README

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:

"nekman/luhn-algorithm": "2.*"

Usage

Use the class like this:

$luhn = new \Nekman\LuhnAlgorithm\LuhnAlgorithm('123456789');
$luhn->isCompletelyValid();

The class contains some static functions as well. This will return the Luhn checksum of a number:

$number = '123456789';
$luhnCheckSum = \Nekman\LuhnAlgorithm\LuhnAlgorithm::calculateChecksum($number);

Personnummer

If you'd like to validate the input to the class, extend it and do a regex check. In the file Personnummer.php, I have extended the class to make sure that the input is a valid Swedish national security id.