CardInput
Number, expiry and CVC as one component with one canonical value. The grouping reflows as the brand is detected — 4-4-4-4 for Visa, 4-6-5 for Amex — and the CVC length follows it. Focus advances to the expiry only when the number is both a valid length for its brand and passes Luhn, because Visa accepts 16, 18 and 19 digits and advancing on the first valid length strands anyone with a 16-digit card.
$ npx shadcn@latest add https://input-cn.vercel.app/r/card-input.jsonHand this to Claude Code
Most people reach this component through an agent rather than by reading the page. Pick how you want it wired and take a prompt that already carries the canonical value, the real prop names and the mistakes worth avoiding.
Nothing runs on its own. The link opens the tool with the prompt typed into the box; you read it and press Enter. If the button does nothing, Claude Code is not installed on this machine — use Copy prompt instead.
Live demo
Try 4242… then 3782… — the grouping reflows to 4-6-5.
value = "" · digits only
Constraints
Validation rules, declared as props. Each one produces its own message and its own data-rule value, so a test can assert the rule rather than the sentence.
Props
Shared props
Implemented identically by all eleven components. These tables are generated from the source interfaces at build time, so a renamed prop changes this page rather than quietly making it wrong.
With react-hook-form
import { useForm, Controller } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { cardSchema } from "@inputcn/card/schema"
import { CardInput } from "@/components/ui/card-input"
import { z } from "zod"
// The companion schema validates the CANONICAL value, so the resolver and the
// field can never disagree about what "valid" means.
const schema = z.object({ card: cardSchema() })
export function Example() {
const { control } = useForm({ resolver: zodResolver(schema) })
return (
<Controller
name="card"
control={control}
render={({ field, fieldState }) => (
<CardInput
label="Card details"
{...field}
aria-invalid={fieldState.invalid}
/>
)}
/>
)
}With a Server Action
import { CardInput } from "@/components/ui/card-input"
export default function Page() {
return (
<form action={save}>
<CardInput name="card" label="Card details" />
<button>Save</button>
</form>
)
}
async function save(data: FormData) {
"use server"
// The hidden canonical input carries the real value, not the display text.
const card = data.get("card") // "4242424242424242"
}Keyboard
Worth knowing
This is not a PCI-compliant capture path on its own. It is an input; the compliance boundary is your payment processor iframe.
Emits string, for example "4242424242424242". Keyboard operation is covered by automated tests; screen readers have not been verified yet.