StealThis .dev

Form — Card / payment input group

A polished credit-card payment field group with a live, flipping card preview. The number input formats into brand-correct groups as you type, detects Visa, Mastercard, Amex and Discover from the prefix, and runs a real Luhn checksum for inline validation. Expiry is masked to MM/YY with a past-date guard, the CVC adapts to 3 or 4 digits by brand and flips the card to its back on focus, and cardholder name plus billing postal code round out a fully keyboard-accessible, demo-only checkout.

Open in Lab
html css vanilla-js
Targets: JS HTML

Code

Card / payment input group

A self-contained checkout card field set built entirely in vanilla JavaScript. As you type the card number it formats into the right groups — four-by-four for most networks, the 4-6-5 layout for American Express — while the issuing brand is detected from the leading digits and surfaced both inside the input and on a 3D card preview drawn in CSS. A live Luhn checksum validates the number the moment a complete card is entered, so invalid sequences are flagged inline with aria-invalid and a helper message rather than waiting for submit.

The animated preview mirrors every field in real time: the masked number, the uppercased cardholder name, and the MM/YY expiry. The expiry input is masked and guarded against past dates, and the CVC field adapts its required length to the detected brand (four digits for Amex, three otherwise). Focusing the CVC flips the card to reveal the signature strip and security code, exactly as you would turn a physical card over.

Validation runs on blur and again on submit, focusing the first invalid field and announcing problems through an aria-live toast. A successful submit simulates processing and then reveals a “Payment confirmed (demo)” state showing the brand and last four digits, with a button to start over. Everything is client-side, the layout collapses cleanly to a single column at 360px, and motion is disabled under prefers-reduced-motion.

Demo only — no network requests, no charges, and only fictional or test card data.