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 tests
    Factory::makeFromNumber($card_number)
  • factory.priority-order · Covered · Core · 18 tests
    Factory::makeFromNumber: the order in which brands are tried
  • factory.whitespace · Diverged · Core
    Factory::makeFromNumber and Card::setCardNumber with whitespace in the number
  • factory.non-string-input · Covered · Core · 6 tests
    Factory::makeFromNumber with a value that is neither a string nor an integer
  • card.construct-and-state · Diverged
    Card::__construct($card_number = '')
  • card.set-number · Covered · Core · 6 tests
    Card::setCardNumber($card_number)
  • card.is-valid-number · Covered · Core · 10 tests
    Card::isValidCardNumber()
  • card.luhn-checksum · Covered · Core · 7 tests
    the Luhn check made by Card::isValidCardNumber()
  • card.metadata · Covered · Core · 16 tests
    Card::type(), Card::name() and Card::brand()
  • card.pattern-property · Diverged
    the public static Card::$pattern
  • card.is-valid-cvc · Covered · Core · 37 tests
    Card::isValidCvc($cvc)
  • card.is-valid-cvc-length · Covered · Core · 34 tests
    Card::isValidCvcLength($cvc, $available_lengths = [3, 4])
  • card.marker-contract · Diverged
    Contracts\CreditCard
  • card.custom-implementation · Diverged
    the checks Card::__construct() makes on a custom card class
  • card.errors-redacted · Diverged · Core
    Exceptions\CreditCardException and its subclasses
  • brand.dankort · Covered · 6 tests
    Cards\Dankort
  • brand.forbrugsforeningen · Covered · 6 tests
    Cards\Forbrugsforeningen
  • brand.maestro · Covered · Core · 24 tests
    Cards\Maestro
  • brand.visaelectron · Covered · 14 tests
    Cards\VisaElectron
  • brand.elo · Covered · 44 tests
    Cards\Elo
  • brand.amex · Covered · Core · 7 tests
    Cards\AmericanExpress
  • brand.dinersclub · Covered · 10 tests
    Cards\DinersClub
  • brand.discover · Covered · Core · 11 tests
    Cards\Discovery
  • brand.jcb · Covered · 13 tests
    Cards\Jcb
  • brand.hipercard · Diverged
    Cards\Hipercard
  • brand.mastercard · Covered · Core · 19 tests
    Cards\Mastercard
  • brand.unionpay · Covered · 13 tests
    Cards\UnionPay
  • brand.visa · Covered · Core · 10 tests
    Cards\Visa
  • brand.mir · Covered · 6 tests
    Cards\Mir
  • brand.troy · Covered · 13 tests
    Cards\Troy
  • expiration.validate · Covered · Core · 13 tests
    ExpirationDateValidator::validate($year, $month) and ExpirationDateValidator::isValid()
  • expiration.year · Diverged · Core
    the year handling of ExpirationDateValidator
  • expiration.month · Diverged · Core
    the month handling of ExpirationDateValidator
  • expiration.boundaries · Covered · Core · 11 tests
    ExpirationDateValidator::isValid() at the end of the expiration month
  • rule.card-number · Covered · Core · 17 tests
    CardNumber::passes($attribute, $value)
  • rule.card-number.messages · Covered · Core · 9 tests
    CardNumber::message() and the CardNumber::MSG_CARD_* constants
  • rule.card-cvc · Covered · Core · 15 tests
    CardCvc::__construct($card_number) and CardCvc::passes($attribute, $value)
  • rule.card-expiration-year · Covered · Core · 13 tests
    CardExpirationYear::__construct($month) and CardExpirationYear::passes($attribute, $value)
  • rule.card-expiration-month · Covered · Core · 11 tests
    CardExpirationMonth::__construct($year) and CardExpirationMonth::passes($attribute, $value)
  • rule.card-expiration-date · Diverged · Core
    CardExpirationDate::__construct(string $format) and CardExpirationDate::passes($attribute, $value)
  • rule.card-expiration-date.messages · Diverged · Core
    CardExpirationDate::message() and the CardExpirationDate::MSG_CARD_EXPIRATION_DATE_* constants
  • rule.messages.translation · Diverged
    the 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

Crates: laravel-rust-credit-card, laravel-rust-credit-card-core · Upstream notices

Documentation