Skip to content
Shubham JangleResources
React

Explore topics

OTP Input Box

Watch the walkthrough
Open on Instagram

Exercise: Build an OTP input group

Render a configurable number of one-character inputs, for example six, and expose the joined value through onChange. Accept digits only and invoke onComplete only when every position is filled.

Requirements

  • Advance focus after valid input; on Backspace clear the current digit or move back from an empty box.
  • Support Arrow Left/Right and pasting multiple digits from the focused position, truncating overflow.
  • Keep the inputs controlled and define replacement behavior for an already-filled position.
  • Label each position and use inputMode="numeric"; preserve leading zeroes by keeping the OTP as a string.

Acceptance checks and discussion

Enter a leading zero, paste too many digits, paste text containing nondigits, and clear a middle box. Check focus boundaries.

The brief above is an original practice specification. The linked sandbox is supporting solution material and may implement a simpler subset of these requirements.

Supporting material