Credit Card
Validate credit card numbers with the Luhn checksum
Credit Card
The creditCard rule validates that a value is a credit card number: 13–19 digits passing the Luhn checksum.
Configuration
| Config flag | Type | Description |
|---|---|---|
creditCard | boolean | Requires a Luhn-valid card number of 13–19 digits. |
validationSchema: {
card: { creditCard: true },
}With a custom message:
card: { creditCard: "Enter a valid card number" }V builder
import { V } from "formify-js";
V.creditCard()
V.creditCard("Enter a valid card number")Default message
Please enter a valid credit card number
Examples
| Value | Result |
|---|---|
4242 4242 4242 4242 | ✅ Valid (Luhn passes) |
4242-4242-4242-4242 | ✅ Valid |
4242 4242 4242 4241 | ❌ Invalid (Luhn fails) |
Things to know
- Spaces and dashes are stripped before validation, so
4242 4242 4242 4242and4242-4242-4242-4242both validate. - The rule checks the checksum and digit count — it does not detect the brand (Visa, Mastercard, …). For formatting as the user types, pair it with the
creditCardformatter (format: "creditCard"). - Empty values pass unless
required: trueis also set.