@letar/forms

Credit Card

Card number input with brand detection, expiry, and CVC

Overview

Form.Field.CreditCard is a compound input for payment card data: number (with auto-detection of Visa, MasterCard, Mir, etc.), expiry date, and CVC.

Basic Usage

<Form initialValue={{ card: { number: '', expiry: '', cvc: '' } }} onSubmit={handleSubmit}>
  <Form.Field.CreditCard name="card" label="Payment Card" />
  <Form.Button.Submit>Pay</Form.Button.Submit>
</Form>

Layouts

Inline — all fields in one row:

<Form.Field.CreditCard name="card" layout="inline" />

Stacked — fields stacked vertically:

<Form.Field.CreditCard name="card" layout="stacked" />

Props

PropTypeDefaultDescription
namestringField group name
labelstringLabel
brandsCardBrand[]allRestrict accepted brands
showBrandIconbooleantrueShow detected brand icon
layout'inline' | 'stacked''inline'Field layout
disabledbooleanfalseDisable input
readOnlybooleanfalseRead-only mode

Value

{ number: '4111111111111111', expiry: '12/28', cvc: '123' }

Brand Detection

Card brand is detected automatically from the first digits: Visa (4), MasterCard (51-55), Mir (2200-2204), American Express (34/37), and more.

Validation

Built-in Luhn algorithm validation for card numbers. Use creditCardSchema for Zod schema validation:

import { creditCardSchema } from '@letar/forms'

const schema = z.object({
  card: creditCardSchema,
})

Live Example

Try the interactive example on forms-example.letar.best.

On this page