Security code

SecurityCodeControl

One box per character for verification codes and PINs, with a callback when the last box is filled.

Overview

SecurityCodeControl renders Length single-character inputs and joins them into one string bound through Value. OnComplete fires when every box holds a character. Type="Numeric" rejects anything but digits and uses type="tel", so phones show the number pad. Each box is an ordinary input: Tab or a click moves between them, a character fills a box and Backspace clears it. The control does not move focus on its own and does not split a pasted code across the boxes.

Examples

#Verification code

Six digits, checked in OnComplete. Fill the boxes in order with Tab between them; the demo code is 492018. Clear resets the bound value, which empties every box.

Example
Razor
C#

We sent a code to +1 (425) ••• 0142. Enter it to continue.

0 of 6 digits entered

Documentation

SecurityCodeControl parameters

ParameterTypeDefaultDescription
Valuestring?nullThe joined characters. Two-way with @bind-Value; a cleared middle box leaves a space.
ValueChangedEventCallback<string?>—Fires after every keystroke that changes a box.
Lengthint6Number of boxes.
TypeSecurityCodeControl.SecurityCodeTypeNumericNumeric accepts digits only and renders type="tel"; AlphaNumeric accepts any character.
OnCompleteEventCallback<string>—Fires with the full code once every box is filled, after ValueChanged.
DisabledboolfalseDisables every box and greys the host. The base Enabled is not read by this control.
CssClass / Style (base)string?nullOn the host element. The base Visible is not applied.
(unmatched attributes)Dictionary<string,object>—Forwarded to the host <div>, not to the boxes.

SecurityCodeType (nested enum)

PropertyTypeDefaultDescription
Numeric—Digits 0–9; other characters are ignored.
AlphaNumeric—Any single character per box; no case folding.

CSS classes

ClassEffect
fx-security-code-host · .disabledInline flex row, 0.5rem gap; disabled greys the boxes and sets cursor: not-allowed.
fx-security-code-cellEach box: 42×48px, bold 1.25rem text, 2px border; focus turns the border blue with a 3px ring.

Colors are fixed in the control's stylesheet; it reads no --fx-* variables. Restyle by overriding these classes.

Keyboard and accessibility

Keyboard

KeyAction
Tab / Shift+TabMove to the next or previous box. The control does not move focus itself.
CharacterFills the box. In Numeric mode only digits are accepted.
BackspaceClears the box; focus stays.
Arrow keysNot handled; the caret moves inside the single-character box.
  • The boxes are plain inputs with maxlength="1" and no accessible name of their own. Put a visible instruction before the control, as above.
  • The host is a <div> without a role; unmatched attributes such as id or data-* land on it.
  • Numeric boxes are type="tel", alphanumeric boxes type="text". A non-digit typed into a numeric box is ignored.
  • Clearing a middle box leaves a gap in Value (a space), so OnComplete waits until that box is filled again.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.