# Validation rules (laravel-rust-credit-card)

> Use the five card rules on a Laravel request or add them to a runtime rule set through the framework's Rule type.

- Package: laravel-rust-credit-card (Laravel for Rust, alpha), crates: `laravel-rust-credit-card`, `laravel-rust-credit-card-core`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-credit-card), [crates.io](https://crates.io/crates/laravel-rust-credit-card/0.1.0), [docs.rs](https://docs.rs/laravel-rust-credit-card/0.1.0), [Changelog](https://oss.bowerbird.si/credit-card/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-credit-card/blob/aa74b5cf59bf07f77714c9f308a7a47bb62633c4/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-credit-card/blob/aa74b5cf59bf07f77714c9f308a7a47bb62633c4/SECURITY.md)
- Based on: [laravel-validation-rules/credit-card](https://github.com/laravel-validation-rules/credit-card): The PHP validation rules whose behaviour this package independently implements, following version 1.12.3.
- PHP parity: full (30 covered, 12 diverged, 0 planned of 42 abilities; 830 fixtures; follows laravel-validation-rules/credit-card 1.12.3; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/credit-card/docs/rules/
- Source: https://github.com/bowerbird-si/laravel-rust-credit-card/blob/aa74b5cf59bf07f77714c9f308a7a47bb62633c4/docs/rules.md

Use the five card rules on a Laravel request or add them to a runtime rule set through the framework's `Rule` type.

```rust
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.

```rust
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.
