PHP code example of nekman / luhn-algorithm

1. Go to this page and download the library: Download nekman/luhn-algorithm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.

/* Start to develop here. Best regards */


nekman / luhn-algorithm example snippets

 use Nekman\LuhnAlgorithm\LuhnAlgorithmFactory;

 $luhn = LuhnAlgorithmFactory::create();

use Nekman\LuhnAlgorithm\Number;

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

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

use Nekman\LuhnAlgorithm\Number;

$number = new Number(12345);

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

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