React Native · Components
OtpInput
One-time password (OTP), verification code and PIN input.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
Verification on the server: the boxes shake on a wrong code (the right code is 123456)
PIN: 4 digits, hidden, underline
License key: letters+digits, uppercase, groups of 4, joined boxes
Custom set (no 0/O and 1/I) and a dot as the separator
Controlled usage
Value: "42"
Import
OtpInput
componentOne-time password (OTP), verification code and PIN input. The code shows in boxes but there is a single TextInput behind them: SMS code suggestions on iOS (oneTimeCode), SMS autofill on Android (sms-otp), pasting and screen readers work without issues. The code inside a pasted SMS is found ("Your code: 482-913" → 482913). The same rules as OtpInput on web (@yasinsensoy/core/otp-charset).
Examples
OtpCharset
typeCharacters that can be typed in a one-time code field (OtpInput).
"numeric": digits only (0-9). Opens the numeric keyboard on mobile."alphabetic": letters of the English alphabet only (A-Z)."alphanumeric": letters and digits (A-Z,0-9)."hex": hexadecimal (0-9,A-F)."any": any character except whitespace.- Any other string: only the characters in that string (e.g. a set without
0/Oand1/Ito avoid confusion:"ABCDEFGHJKLMNPQRSTUVWXYZ23456789"). Can also be passed from server components. RegExp: expression tested against each character (e.g./[0-9A-F]/i). Can't be passed from a server component to the client; only in"use client"files.
OtpCasing
typeCase letters are converted to.
OtpInputVariant
typeLook of the boxes: separate boxes, joined boxes or an underline.
OtpInputHandle
interfaceMethods of the OtpInput ref.
| Name | Type | Description |
|---|---|---|
focus | () => void | Focuses the field (the keyboard opens). |
blur | () => void | Releases focus. |
clear | () => void | Clears the code and focuses the first box. |
OtpInputProps
interfaceProps of OtpInput.
Extends: FieldProps
| Name | Type | Default | Description |
|---|---|---|---|
ref? | Ref<OtpInputHandle> | Ref: focus, blur, clear. | |
length? | number | 6 | Number of boxes. |
charset? | OtpCharset | "numeric" | Characters that can be typed. See OtpCharset. |
casing? | OtpCasing | Converts letters to upper or lower case. | |
value? | string | Code (controlled). | |
defaultValue? | string | "" | Initial code (uncontrolled). |
onValueChange? | (value: string) => void | When the code changes. | |
onComplete? | (value: string) => void | When all boxes are filled. | |
groups? | number | readonly number[] | Groups the boxes: 3 → 123-456, [3, 2, 3]. | |
separator? | ReactNode | a hyphen | Separator between groups. |
mask? | boolean | Characters are hidden (PIN); a typed one is visible briefly. | |
placeholder? | string | Character shown in an empty box (e.g. "○"). | |
size? | Size | "md" | Box size. |
variant? | OtpInputVariant | (string & {}) | "outline" | Variant. |
effect? | EffectProp | Effect of the boxes ("glow", "beam", "border"…); stays on in the box to type into. Defaults to appearance.defaults.otpInput.effect. See BuiltinEffect. | |
autoFocus? | boolean | Focuses when opened. | |
onResend? | () => unknown | When given, a "Resend code" link appears below; it counts down resendDelay seconds. If it returns a Promise it waits until it settles. | |
resendDelay? | number | 60 | Resend wait time (seconds). |
accessibilityLabel? | string | Screen reader label. | |
style? | StyleProp<ViewStyle> | Container style. |