Use the five card rules on a Laravel request or add them to a runtime rule set through the framework's Rule type.
use laravel_rust_credit_card::{CardCvc, CardExpirationDate, CardNumber};
#[laravel::input]
#[validate(anyone)]
struct Checkout {
#[validate(required, CardNumber::new())]
card_number: String,
#[validate(required, CardCvc::for_field("card_number"))]
cvc: String,
#[validate(required, CardExpirationDate::new("m/y"))]
expiration: String,
}| Rule | Configuration |
|---|---|
CardNumber::new() | Detects the brand and checks its length and checksum requirements. |
CardCvc::for_field("card_number") | Finds the number in a sibling field. Use for_brand for a known brand or for_number for a number already available to your code. |
CardExpirationYear::month_field("month") | Checks the year against its sibling month. Use month_number(12) for a fixed month. |
CardExpirationMonth::year_field("year") | Checks the month against its sibling year. Use year_number(2030) for a fixed year. |
CardExpirationDate::new("m/y") | Checks a formatted date against the application clock. |
Dates remain valid through their expiration month. Split fields expand two-digit years using the
current century. Formatted dates use PHP's pivot, with 00 through 69 in 2000–2069 and 70
through 99 in 1970–1999.
Call .message(...) to override a rule's message. CardNumber also provides
invalid_message, length_message, and checksum_message. CardExpirationDate
provides format_message and expired_message. The messages module exports PHP's
translation keys for applications that use them.
Browser forms
Submit the PAN and CVC in the body of a POST request. Keep both out of URLs and query strings. Laravel can save the full URL of a GET request in the session as a future redirect target.
Configure date formats and custom brand prefixes in application code. Form inputs supply only the values being validated.
List the submitted PAN and CVC paths with Errors::dont_flash. Laravel otherwise flashes
submitted fields to the session when a browser validation failure redirects back.
laravel::Application::configure().with_errors(|errors, _| {
errors.dont_flash(["card_number", "cvc"]);
});
For a list of cards, exclude the entire collection with errors.dont_flash(["cards"]).
Laravel for Rust 0.2 matches exact paths for old input exclusions. A wildcard path such as
cards.*.cvc leaves list entries in the session.
The rules discard the PAN and CVC after validation and omit them from diagnostics. The checks establish syntactic plausibility. Use your payment provider to verify an account or a security code against the issuer.