nekman/luhn-algorithm 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nekman/luhn-algorithm

最新稳定版本:5.0.2

Composer 安装命令:

composer require nekman/luhn-algorithm

包简介

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

README 文档

README

Build Status Coverage Status

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.

Installation

Install with Composer:

composer require nekman/luhn-algorithm

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.

The Number class 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

This project complies with Semantic Versioning.

Changelog

For a complete list of changes, and how to migrate between major versions, see releases page.

Buy me a coffee

"Buy Me A Coffee"

If you appreciate my work, then consider buying me a coffee. Donations are completely voluntary.

统计信息

  • 总下载量: 776.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 0
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-13