OTP Input
The OtpInput field renders a series of single-character inputs for entering a one-time password, such as a verification code. It handles pasted codes and may submit the form automatically once every input is filled.
Basic Usage
By default, the field renders six numeric inputs and adds the nullable, digits:6, and numeric validation rules. To reject blank values, add the required method:
use InertiaUI\Forms\Fields\OtpInput;
OtpInput::make('code');Length
To change the number of inputs, you may use the length method:
OtpInput::make('code')->length(4);The configured length drives the validation rule. Numeric mode uses Laravel's digits rule, while alphanumeric mode and numeric(false) use the string size rule.
Input Type
Numeric (Default)
Numeric mode is the default. Vue and React only accept the digits 0 to 9, and the field adds the numeric validation rule. The managed length rule is digits:
OtpInput::make('code')->numeric();Call the numeric method to switch back from alphanumeric. To permit any character, call numeric(false). Unrestricted fields use the string and size rules, so arrays are still rejected.
Alphanumeric
The alphanumeric method accepts letters and digits in Vue and React and adds the alpha_num validation rule instead. Punctuation is filtered out before the value is submitted, and the length rule becomes the string size rule:
OtpInput::make('verification')->alphanumeric();For direct components, pass numeric={false} and alphanumeric in React, or :numeric="false" and alphanumeric in Vue.
Grouping and Separators
Separator
The separator method adds a visual separator, such as a dash or a dot, between groups of inputs. The separator only renders once you also set a group size:
OtpInput::make('code')
->groupSize(3)
->separator('-');Group Size
The groupSize method splits the inputs into groups. Combined with a separator, it creates the classic "3-3" or "4-2" verification code look:
// 123-456
OtpInput::make('code')
->length(6)
->groupSize(3)
->separator('-');Display and Entry
These methods control how the inputs display characters, and how the field takes focus, fills in, and submits a code.
Password Mode
The password method masks the entered characters with dots, like a password field:
OtpInput::make('pin')->password();Placeholder
The placeholder method sets a placeholder character for empty inputs:
OtpInput::make('code')->placeholder('·');Autofocus
The autofocus method focuses the first input when the page loads:
OtpInput::make('code')->autofocus();Auto Submit
The autoSubmit method submits the form once every input is filled:
OtpInput::make('code')->autoSubmit();This works well for verification flows without a separate submit button.
Web OTP
The Web OTP API lets the browser fill in verification codes received by SMS. It's enabled by default, starts when the field receives focus, and works on Chrome for Android.
To disable it, pass false to the webOtp method:
OtpInput::make('code')->webOtp(false);Auto-Submitting Verification Code
The following field combines the options above into a six-digit verification code that submits itself:
OtpInput::make('verification_code')
->label('Verification Code')
->help('Enter the 6-digit code sent to your phone')
->length(6)
->numeric()
->groupSize(3)
->separator('-')
->autoSubmit()
->required();OtpInput also supports the shared label, help text, disabled and required state, validation, visibility, and styling APIs. See Validation, Conditional Visibility, Authorization, and Styling.
Using the Component Directly
For manual form rendering, pass the serialized field props described in Manual Usage. For standalone use, bind a string value directly:
<script setup lang="ts">
import { OtpInput } from '@inertiaui/form-vue/components'
import { ref } from 'vue'
const backupCode = ref('')
const trackPaste = () => {}
</script>
<template>
<OtpInput
v-model="backupCode"
id="backup-code"
name="backup_code"
label="Backup code"
help="Enter the 8-character recovery code."
:length="8"
:numeric="false"
alphanumeric
password
autofocus
auto-submit
separator="-"
:group-size="4"
placeholder="*"
:web-otp="false"
data-testid="backup-code"
@paste="trackPaste"
/>
</template>import { useState } from 'react'
import { OtpInput } from '@inertiaui/form-react/components'
export function BackupCodeField() {
const [backupCode, setBackupCode] = useState('')
const trackPaste = () => {}
return (
<OtpInput
value={backupCode}
onValueChange={setBackupCode}
id="backup-code"
name="backup_code"
label="Backup code"
help="Enter the 8-character recovery code."
length={8}
numeric={false}
alphanumeric
password
autofocus
autoSubmit
separator="-"
groupSize={4}
placeholder="*"
webOtp={false}
data-testid="backup-code"
onPaste={trackPaste}
/>
)
}Native attributes and listeners are forwarded to the underlying OTP inputs. See Native Attributes And Events.