EN
Getting started
69 · Forms

Verification code

Shows a separate box for each digit of a one-time code sent by SMS or email. The boxes accept digits only; a pasted code is spread across the boxes automatically.

PRO acun:input-otp
01

Basic usage

By default 6 boxes are shown. When a digit is typed, focus moves to the next box, and Backspace in an empty box goes back to the previous one; non-digit characters such as letters do not stay in the box. When a code is pasted, the digits fill the boxes in order and focus moves to the box after the last digit. The first box has autocomplete="one-time-code", so phones can suggest the SMS code automatically. Screen readers announce each box as "Digit 1 of 6", "Digit 2 of 6".

LIVE EXAMPLE
<acun:input-otp label="Code sent by SMS" />
PropValues
labelLabel above the boxes
02

Number of digits

length sets the number of boxes. The name of the hidden field the code is submitted with is changed with name; if omitted, the name of the wire:model property is used, or code if that is missing too. You can give an initial code with value.

LIVE EXAMPLE
<acun:input-otp :length="4" name="pin" label="4-digit PIN" />
PropValues
length6 (default)
namewire:model name or code
valueInitial code
03

In a form and with Livewire

In a classic form, the digits in the boxes are joined and submitted with a hidden field. wire:model is two-way: the typed code is written to the property, and a code set by the server ($this->code = '482615', reset()) is spread across the boxes. The hidden field takes part in the form's change tracking; the boxes themselves do not count. Other attributes such as wire:key and class are added to the outer container. The component does not show validation errors itself; add the message below it with @error.

BLADE
{{-- Classic form: the code is submitted as "code" --}}
<form method="POST" action="{{ route('verification.check') }}">
    @csrf
    <acun:input-otp label="Verification code" />
    <acun:button type="submit" class="mt-4 w-full">Verify</acun:button>
</form>

{{-- Livewire --}}
<acun:input-otp wire:model="code" label="Verification code" />
@error('code')
    <p class="text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
PropValues
wire:modelThe joined code; two-way
API

Props and slots

The values the component accepts.

PropDefaultDescription
length6Number of boxes (digits)
namenullName of the hidden field the code is submitted with; otherwise the wire:model name, or code if that is missing too
labelnullLabel above the boxes
valuenullInitial code (without wire:model / x-model); non-digit characters are dropped
wire:model / x-model — Two-way: a code coming from the server is spread across the boxes
Acun UI · Verification codeDetailed usage and examples