Skip to content

Implementation of the Luhn Algorithm in PHP

License

Notifications You must be signed in to change notification settings

p16/Luhn-Algorithm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Luhn Algorithm in PHP

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.

About

Implementation of the Luhn Algorithm in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%