Formify Docs

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 flagTypeDescription
creditCardbooleanRequires 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

ValueResult
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 4242 and 4242-4242-4242-4242 both 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 creditCard formatter (format: "creditCard").
  • Empty values pass unless required: true is also set.

On this page