Laravel for Rust Alpha
laravel-rust-credit-card
Validate card numbers, security codes and expiration dates in Laravel for Rust.
Rust port of [laravel-validation-rules/credit-card](https://github.com/laravel-validation-rules/credit-card): credit card number, expiration date, and CVC validation rules.
Read the docs Source on GitHub
cargo add laravel-rust-credit-card- Latest release
- 0.1.0, 2026-12-04
- Maintenance
- Active
- Framework
- laravel-rust 0.2.x
- MSRV
- Rust 1.99 or later
- Licence
- MIT
PHP parity
Follows laravel-validation-rules/credit-card 1.12.3 (commit 194f41f4fc7d). Last verified .
- Parity level
- Full
- Abilities
- 42
- Covered
- 30
- Diverged
- 12
- Planned
- 0
- PHP fixtures
- 830
Fixtures are generated by PHP itself: PHP 8.5, laravel-validation-rules/credit-card 1.12.3, laravel/framework v13.45.0, nesbot/carbon 3.15.2.
Coverage by ability
-
factory.make-from-number· Covered · Core · 13 testsFactory::makeFromNumber($card_number) -
factory.priority-order· Covered · Core · 18 testsFactory::makeFromNumber: the order in which brands are tried -
factory.whitespace· Diverged · CoreFactory::makeFromNumber and Card::setCardNumber with whitespace in the number -
factory.non-string-input· Covered · Core · 6 testsFactory::makeFromNumber with a value that is neither a string nor an integer -
card.construct-and-state· DivergedCard::__construct($card_number = '') -
card.set-number· Covered · Core · 6 testsCard::setCardNumber($card_number) -
card.is-valid-number· Covered · Core · 10 testsCard::isValidCardNumber() -
card.luhn-checksum· Covered · Core · 7 teststhe Luhn check made by Card::isValidCardNumber() -
card.metadata· Covered · Core · 16 testsCard::type(), Card::name() and Card::brand() -
card.pattern-property· Divergedthe public static Card::$pattern -
card.is-valid-cvc· Covered · Core · 37 testsCard::isValidCvc($cvc) -
card.is-valid-cvc-length· Covered · Core · 34 testsCard::isValidCvcLength($cvc, $available_lengths = [3, 4]) -
card.marker-contract· DivergedContracts\CreditCard -
card.custom-implementation· Divergedthe checks Card::__construct() makes on a custom card class -
card.errors-redacted· Diverged · CoreExceptions\CreditCardException and its subclasses -
brand.dankort· Covered · 6 testsCards\Dankort -
brand.forbrugsforeningen· Covered · 6 testsCards\Forbrugsforeningen -
brand.maestro· Covered · Core · 24 testsCards\Maestro -
brand.visaelectron· Covered · 14 testsCards\VisaElectron -
brand.elo· Covered · 44 testsCards\Elo -
brand.amex· Covered · Core · 7 testsCards\AmericanExpress -
brand.dinersclub· Covered · 10 testsCards\DinersClub -
brand.discover· Covered · Core · 11 testsCards\Discovery -
brand.jcb· Covered · 13 testsCards\Jcb -
brand.hipercard· DivergedCards\Hipercard -
brand.mastercard· Covered · Core · 19 testsCards\Mastercard -
brand.unionpay· Covered · 13 testsCards\UnionPay -
brand.visa· Covered · Core · 10 testsCards\Visa -
brand.mir· Covered · 6 testsCards\Mir -
brand.troy· Covered · 13 testsCards\Troy -
expiration.validate· Covered · Core · 13 testsExpirationDateValidator::validate($year, $month) and ExpirationDateValidator::isValid() -
expiration.year· Diverged · Corethe year handling of ExpirationDateValidator -
expiration.month· Diverged · Corethe month handling of ExpirationDateValidator -
expiration.boundaries· Covered · Core · 11 testsExpirationDateValidator::isValid() at the end of the expiration month -
rule.card-number· Covered · Core · 17 testsCardNumber::passes($attribute, $value) -
rule.card-number.messages· Covered · Core · 9 testsCardNumber::message() and the CardNumber::MSG_CARD_* constants -
rule.card-cvc· Covered · Core · 15 testsCardCvc::__construct($card_number) and CardCvc::passes($attribute, $value) -
rule.card-expiration-year· Covered · Core · 13 testsCardExpirationYear::__construct($month) and CardExpirationYear::passes($attribute, $value) -
rule.card-expiration-month· Covered · Core · 11 testsCardExpirationMonth::__construct($year) and CardExpirationMonth::passes($attribute, $value) -
rule.card-expiration-date· Diverged · CoreCardExpirationDate::__construct(string $format) and CardExpirationDate::passes($attribute, $value) -
rule.card-expiration-date.messages· Diverged · CoreCardExpirationDate::message() and the CardExpirationDate::MSG_CARD_EXPIRATION_DATE_* constants -
rule.messages.translation· Divergedthe rules' message() methods and trans('validation.credit_card.*')
Differences from PHP (12)
Factory::makeFromNumber and Card::setCardNumber with whitespace in the number- ASCII whitespace is stripped before the brand is recognised, so recognition and direct validation agree; PHP matches the brand first and rejects a leading space or a space inside a prefix.
Card::__construct($card_number = '')- A card is an immutable validated value: a failed validation returns an error and leaves no half-updated instance, and "0" is checked as a one-digit number instead of being treated as unset.
the public static Card::$pattern- Built-in brand rules are fixed and a custom brand is a typed specification; PHP exposes a public static pattern on each card class that a program can change.
Contracts\CreditCard- Cards and brands are concrete types; PHP's marker interface is empty and carries no behaviour.
the checks Card::__construct() makes on a custom card class- A custom card is a typed specification checked when it is built, and requires both length lists to contain positive integers. PHP checks an untyped subclass and accepts list entries that cannot match any input.
Exceptions\CreditCardException and its subclasses- Errors name the failed check and never contain the card number or the CVC; PHP's exception messages contain the card number.
Cards\Hipercard- Both Hipercard prefix rules are anchored at the start of the number; PHP's second rule matches anywhere in the string, so some longer numbers fail on length in PHP and match no brand in the port.
the year handling of ExpirationDateValidator- One clock supplies the century for two-digit years and the comparison date, and a NUL byte is invalid input; PHP mixes the system clock with the test clock and trims NUL bytes. Direct PHP calls in coercive mode can accept integral floats.
the month handling of ExpirationDateValidator- A NUL byte is invalid input; PHP trims it from both ends of the month.
CardExpirationDate::__construct(string $format) and CardExpirationDate::passes($attribute, $value)- The four-digit year is kept as parsed, a NUL byte and a format token the port does not support are malformed input, and a format needs at least one token; PHP can expand years from 0010 to 0099 to the current century, raises an uncaught ValueError on NUL and parses every DateTime token.
CardExpirationDate::message() and the CardExpirationDate::MSG_CARD_EXPIRATION_DATE_* constants- The rule is stateless, so each value gets its own failure message; a reused PHP rule reports the message of its previous failure.
the rules' message() methods and trans('validation.credit_card.*')- Rules return a default English message and export PHP's translation keys as constants; PHP returns the key itself and ships no translations.
Built on
- laravel-validation-rules/credit-card: The PHP validation rules whose behaviour this package independently implements, following version 1.12.3.
Crates: laravel-rust-credit-card, laravel-rust-credit-card-core
· Upstream notices
Documentation
- OverviewRust port of laravel-validation-rules/credit-card: credit card number, expiration date, and CVC validation rules.
- Getting startedInstall the adapter to add card number, security code, and expiration checks to a Laravel for Rust request.
- Validation rulesUse the five card rules on a Laravel request or add them to a runtime rule set through the framework's Rule type.
- Framework-free validationThe core crate validates card numbers, security codes, and expiration dates with an explicit clock for date checks.
- Migrating from PHPMap calls from laravel-validation-rules/credit-card to the Rust types, including immutable card metadata and typed custom brand definitions.
- ChangelogWhat changed in each release of laravel-rust-credit-card: additions, changes and fixes.