Format a credit card number input in React: 4-4-4-4 spacing, brand detection and a Luhn check

A card field should add the spaces as you type, keep the caret where you were editing, know Amex from Visa before the fourth digit, and catch a typo before the payment call. This page is the code: one formatter that knows each brand's grouping and length, a Luhn check, a React input that puts the caret back after reformatting, and the expiry and CVC rules that go with it.

Credit Card Checkout V1, preview

By buying you agree to the Terms.

Ready forCursorv0Lovableshadcn CLI

Full product pageReact · Tailwind · TypeScript