Migrating from PHP

laravel-rust-credit-card Alpha Laravel for Rust

Map calls from laravel-validation-rules/credit-card to the Rust types, including immutable card metadata and typed custom brand definitions.

PHPRust
Factory::makeFromNumber($number)Card::parse(number)
new Visa($number) or setCardNumber($number)Brand::Visa.parse(number)
$card->isValidCvc($cvc)card.is_valid_cvc(cvc)
Card::isValidCvcLength($cvc, $lengths)is_valid_cvc_length(cvc, lengths)
ExpirationDateValidator::validate($year, $month)YearMonth::parse(year, month, today)
new CardNumber()CardNumber::new()
new CardCvc($cardNumber)CardCvc::for_number(number) or CardCvc::for_field("card_number")
new CardExpirationYear($month)CardExpirationYear::month(month) or CardExpirationYear::month_field("month")
new CardExpirationMonth($year)CardExpirationMonth::year(year) or CardExpirationMonth::year_field("year")
new CardExpirationDate('m/y')CardExpirationDate::new("m/y")
Cards\DiscoveryBrand::Discover
Custom card subclassCardSpec::builder(...)

Rust strips ASCII whitespace before detecting the brand. Its failures omit submitted values, and rule messages are English by default. See the rules guide for message overrides and the application setting that keeps card fields out of browser sessions.

Input differences

  • A custom card specification requires nonempty PAN and CVC length lists containing positive integers. There is no package-imposed maximum.
  • Split expiration validation accepts text and integers. The Laravel rules reject floats in both languages. A direct, coercive PHP call can also accept integral floats.
  • A formatted expiration date preserves its parsed four-digit year. For example, PHP can reinterpret the year in 0026-12 as 2026 after parsing. The port treats year 0026 as outside the accepted range and reports an invalid expiration date.