OTP Paste Input

Pulls the right one-time code out of a whole pasted SMS or email, ignoring phone numbers and amounts, and accepts digits in any script.

StopsOTP verification fails on paste

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/otp-paste-input.json

The files land in your project. They're yours to edit.

Usage

otp-paste-input-usage.tsx
import { OtpPasteInput } from "@/components/ui/otp-paste-input"

<OtpPasteInput ref={inputRef} onComplete={setVerified} onValueChange={() => setVerified(undefined)} />

What it catches

  • Whole SMS or email pasted instead of just the code
  • Phone numbers, amounts, account endings and order numbers mistaken for the code
  • Full-width, Devanagari or Arabic-Indic digits from other keyboards
  • Runs of the wrong length

Props

OtpPasteInput props
PropTypeDefault
length

Number of digits in the code.

number6
label

Visible label.

string"Verification code"
hint

Helper text shown until something is pasted.

string"Paste the whole message if you like. We'll find the code."
value

Controlled value (digits only).

string—
defaultValue

Initial value when uncontrolled.

string""
onValueChange

Called with the digits entered so far.

(value: string) => void—
onComplete

Called once all `length` digits are in.

(code: string) => void—
foundMessage

Shown after a code was picked out of a longer message.

(code: string) => string(code) => `Found ${code} in the pasted message.`
notFoundMessage

Shown when a paste held no code of the right length.

(length: number) => string(n) => `Couldn't find a ${n}-digit code in what you pasted.`

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible label; input is described by a polite notice region
  • Digit boxes are a visual layer marked aria-hidden over one real input
  • Notice icons are aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Verify the code server-side with expiry, attempt limits and rate limiting.

  • Picks the likeliest code; unusual message formats can still confuse it
  • Fixed code length (length prop)
  • Doesn't verify the code; your server does

What it stops

OTP verification fails on paste

Also known as

otp · one-time code · verification code · sms code · 2fa · pin input · login · mobile verification

Field type

Dependencies

Pairs well with