Download the PHP package dragon-code/card-number without Composer
On this page you can find all versions of the php package dragon-code/card-number. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dragon-code/card-number
More information about dragon-code/card-number
Files in dragon-code/card-number
Package card-number
Short Description Generation and verification of card numbers using Luhn's algorithm.
License MIT
Informations about the package card-number
Card Number using Luhn's algorithm
Introduction
Generation and verification of card numbers using Luhn's algorithm: credit, customer loyalty and others.
Installation
To get the latest version of Card Number
, simply require the project using Composer:
Or manually update require
block of composer.json
and run composer update
console command.
Usage
Validation
You can validate any numbers with the Luhn algorithm with any input format.
For example:
You can validate bank card numbers. To do this, pass the card type as the second argument:
You can also check for invalid numbers:
In addition to numerical values, you can also validate number-letter combinations. For example:
List of available validation types:
Type | Code | Enum |
---|---|---|
AmericanExpress | amex |
DragonCode\CardNumber\Enums\CardType::americanExpress |
Chars Number | chars |
DragonCode\CardNumber\Enums\CardType::chars |
Dankort | dankort |
DragonCode\CardNumber\Enums\CardType::dankort |
DinersClub | dinersclub |
DragonCode\CardNumber\Enums\CardType::dinersClub |
Discovery | discovery |
DragonCode\CardNumber\Enums\CardType::discovery |
Forbrugsforeningen | forbrugsforeningen |
DragonCode\CardNumber\Enums\CardType::forbrugsforeningen |
HiperCard | hipercard |
DragonCode\CardNumber\Enums\CardType::hiperCard |
Jcb | jcb |
DragonCode\CardNumber\Enums\CardType::jcb |
Maestro | maestro |
DragonCode\CardNumber\Enums\CardType::maestro |
MasterCard | mastercard |
DragonCode\CardNumber\Enums\CardType::masterCard |
Mir | mir |
DragonCode\CardNumber\Enums\CardType::mir |
Ralf Ringer | ralfringer |
DragonCode\CardNumber\Enums\CardType::ralfRinger |
Troy | troy |
DragonCode\CardNumber\Enums\CardType::troy |
Unionpay | unionpay |
DragonCode\CardNumber\Enums\CardType::unionPay |
Visa | visa |
DragonCode\CardNumber\Enums\CardType::visa |
VisaElectron | visaelectron |
DragonCode\CardNumber\Enums\CardType::visaElectron |
Yves Rocher | yvesrocher |
DragonCode\CardNumber\Enums\CardType::yvesRocher |
Custom Validators
In some cases there may not be enough built-in validators and therefore you can easily use your own.
To do this, create a class and inherit it from the abstract DragonCode\CardNumber\Validators\CardValidator
,
and then pass a reference to it in the cardType
parameter:
Generation
You can also easily generate any numbers using the Luhn algorithm:
You can also use the formatter to format the resulting value:
Formatters
You can also create your own formatter.
To do this, create a class and inherit it from the DragonCode\CardNumber\Formatters\Formatter
abstract class:
And use this one:
List of available formatters:
DragonCode\CardNumber\Formatters\DefaultFormatter
DragonCode\CardNumber\Formatters\BankFormatter
DragonCode\CardNumber\Formatters\LoyaltyFormatter
DragonCode\CardNumber\Formatters\LoyaltyCharFormatter
In addition to numeric formatters, you can also use number-letter combinations.
For example, using the DragonCode\CardNumber\Formatters\LoyaltyCharFormatter
formatter,
you can generate a letter code instead of a numeric number, which will be valid when
verified by the Luhn's algorithm:
Factories
In addition, you can specify factories as an incoming identifier parameter. In this way, you can form unique identification rules using fluent methods.
This is useful when, for example, you create a customer loyalty card number and want to specify in its number the year of issue as well as its level.
List of available factories:
DragonCode\CardNumber\Factories\BankFactory
DragonCode\CardNumber\Factories\CustomerFactory
Laravel
If you use the Laravel framework, you can also use the validation rule:
You can also check bank cards:
License
This package is licensed under the MIT License.