Bank Input

Iranian card-number (CardNumberInput) and Sheba/Shaba (ShabaInput) text fields that normalize pasted input, format digits into groups, and detect the issuing bank to show its logo. They are built on InputGroup and suit payment and bank-account forms.

Bank Input
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @persianlabsui/bank-input

Requires @persianlabsui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { CardNumberInput } from "@/components/ui/bank-input"export function CardField() {  return <CardNumberInput aria-label="Card number" />}
  • Collecting an Iranian bank card number (16 digits) in checkout, wallet, or payout forms where the bank should be recognized visually
  • Collecting a Sheba (IR…) account number where the user should not have to type the IR prefix
  • Accepting pasted card numbers or Sheba values that contain spaces, dashes, or Persian digits, and normalizing them automatically
  • Showing the detected bank logo next to the field, or reacting to the detected bank through onBankChange

Examples

Uncontrolled card number

Basic usage with an accessible label; the component manages its own value and detects the bank automatically.

uncontrolled-card-number.tsx
import { CardNumberInput } from "@/components/ui/bank-input"export function CardForm() {  return (    <CardNumberInput defaultValue="" placeholder="Card number" aria-label="Card number" />  )}

Controlled card number with bank state

Keeps the normalized digits and the detected bank id in React state so the parent can react to both.

controlled-card-number-with-bank-state.tsx
import * as React from "react"import { CardNumberInput } from "@/components/ui/bank-input"import { type IranianBank } from "@/lib/iranian-bank"export function CardWithBank() {  const [value, setValue] = React.useState("")  const [bank, setBank] = React.useState<IranianBank | undefined>(undefined)  return (    <div className="grid gap-2">      <CardNumberInput        value={value}        onValueChange={setValue}        onBankChange={setBank}        aria-label="Card number"      />      <p className="text-muted-foreground text-sm">        {bank ? bank.id : "Bank not detected"}      </p>    </div>  )}

Sheba account with monochrome logo

Uses ShabaInput, which shows the IR prefix and accepts only the account portion, with a monochrome logo and a dash separator.

sheba-account-with-monochrome-logo.tsx
import { ShabaInput } from "@/components/ui/bank-input"export function ShabaField() {  return (    <ShabaInput      defaultValue=""      bankLogo={"mono"}      separator="-"      aria-label="Sheba account number"    />  )}

Hide the bank logo

Sets bankLogo to false so no logo is rendered while digits are still formatted and validated.

hide-the-bank-logo.tsx
import { CardNumberInput } from "@/components/ui/bank-input"export function PlainCardField() {  return <CardNumberInput bankLogo={false} aria-label="Card number" />}

API reference

PropTypeDefaultDescription
valuestring—Controlled value for CardNumberInput (the card digits, normalized) and ShabaInput (the account portion without the IR prefix). Omit it to use the uncontrolled mode.
defaultValuestring""Initial value for uncontrolled use in both CardNumberInput and ShabaInput.
onValueChange(value: string) => void—Called with the normalized digits (no separators) whenever the value changes in CardNumberInput or ShabaInput.
bankLogo"color" | "mono" | false"color"Shows a color or monochrome bank logo once a bank is detected. Pass false to hide the logo.
onBankChange(bank: IranianBank | undefined) => void—Called on each user edit with the detected bank, or undefined when no bank matches.
separatorstring" "Separator inserted after each four-digit group in the displayed value and placeholder.
classNamestring—Class names applied to the InputGroup wrapper; it is merged with the default h-10 class via cn.
...InputGroupInput propsOmit<React.ComponentProps<typeof InputGroupInput>, "value" | "defaultValue" | "onChange" | "type" | "dir">—All other input props (for example placeholder, disabled, aria-label, id, name, onBlur) are forwarded to the underlying InputGroupInput. The type, dir, and onChange props are fixed internally.

Accessibility

  • Always provide an accessible name with aria-label, aria-labelledby, or a associated label element, because the visible IR prefix and placeholder are not a substitute for a label.
  • The input uses inputMode="numeric" to show a numeric keyboard on mobile devices; CardNumberInput sets autoComplete="cc-number" and ShabaInput sets autoComplete="off".
  • spellCheck is disabled and translate="no" is set so that account digits are not translated or flagged by the browser.
  • The bank logo is decorative and marked aria-hidden="true"; convey the detected bank in text if it matters to the user.
  • Caret position is restored after formatting, so users keep their editing location when digits are inserted or removed.
  • Pass aria-invalid and an error message yourself when the number fails validation; the component does not render an error state.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Bank Input" component (persianlabsui/bank-input) from its shadcn registry.1. Install it with: npx shadcn@latest add @persianlabsui/bank-input2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: value, defaultValue, onValueChange, bankLogo, onBankChange, separator, className, ...InputGroupInput props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { CardNumberInput } from "@/components/ui/bank-input"export function CardField() {  return <CardNumberInput aria-label="Card number" />}```

Files & dependencies

  • registry/base/ui/bank-input.tsx
  • registry/base/hooks/use-controllable-state.ts
dependencies@persianlabs/icons
registryDependenciesutils@persianlabsui/input-group@persianlabsui/iranian-bank

Looks similar, elsewhere