Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input OTP examples · Variants

Numeric Only OTP Input OTP for React

A six-digit code field that accepts digits only and opens the numeric keyboard on phones.

Framework
UI library

Most verification codes are digits. This example accepts only digits in its six slots and asks phones for the numeric keyboard, so people never have to switch keyboards to type the code. A line under the field says so.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How is the field limited to digits?

pattern is ^\d+$, a regular expression string that every character must match.

How does the phone show the number pad?

inputMode is numeric on InputOTP, which passes it to its input.

What happens when a code with spaces is pasted?

Characters that aren't digits are rejected, so paste a clean code. The Paste Optimization example strips everything but the digits before filling the field.

Can phones fill in the code from an SMS?

Yes, when the field has autocomplete one-time-code, which the component sets, iOS and Android offer the code from a recent message.

How is the field split?

Each InputOTPGroup joins its slots into one block, and InputOTPSeparator draws a minus between blocks. The separator isn't a character, and index counts straight through the groups, 0 to 5.

What is the line under the field?

A paragraph in text-sm text-muted-foreground, Numeric keyboard on mobile devices. It's a note for the demo; in a real form, say where the code was sent.