BenixBenix DSv1.1.0

OTPInput

OTP / 2FA code input with paste, auto-focus and backspace handling. Numeric by default; supports alphanumeric for backup/recovery codes.

Examples

Numeric (default)

Use for SMS / email verification codes. Accepts only 0-9; paste distributes the digits.

We sent a code to your email.

Current: ∅

<OTPInput
label="Verification code"
required
value={code}
onChange={setCode}
length={6}
helperText="We sent a code to your email."
/>

Alphanumeric (backup / recovery codes)

Use pattern='alphanumeric' for 2FA backup codes, vouchers, recovery keys.

Use one of the 8-character codes from your account settings.

Current: ∅

<OTPInput
label="Backup code"
pattern="alphanumeric"
length={8}
value={backup}
onChange={setBackup}
/>

Shorter (4 digits)

<OTPInput label="PIN" value={code} onChange={setCode} length={4} />

Error state

Invalid code. Please try again.

<OTPInput
label="Verification code"
value=""
onChange={() => {}}
error="Invalid code. Please try again."
/>

API Reference

Props of the OTPInput component.

PropTypeDefaultDescription
value*string——
onChange*(value: string) => void——
onComplete(value: string) => void—Fired when all fields are filled.
lengthnumber6—
pattern'numeric' | 'alphanumeric''numeric'Allowed characters. alphanumeric accepts letters + digits.
labelstring——
requiredbooleanfalse—
helperTextstring——
errorstring | boolean——
autoFocusbooleantrue—
align'start' | 'center''start'—
disabledbooleanfalse—