All Challenges

OTP 6-Digit Auto-Focus & Clipboard Paste Input

ReactMediumPhonePePaytmCRED
30:00

Problem Brief

Build a 6-digit OTP verification input supporting digit-only entry, auto-focus advance, Backspace rewind, and full 6-digit paste.

Requirements

  • Render 6 `<input class="otp-digit">` boxes inside `[data-testid="otp-group"]`.
  • Entering a single digit moves focus to the next input and updates `[data-testid="otp-value"]`.
  • Pressing `Backspace` on an empty box clears/focuses the previous box.
  • Pasting `"482910"` distributes digits across all 6 inputs cleanly.
Progressive Hints (1)
  • Handle `paste` with `e.preventDefault()`, extract `/\D/g` stripped digits, fill inputs 0..5, and sync summary.
Reference Solution

Stuck? Load the verified reference code into your editor.

Automated Test Suite

2 Test Cases Ready
  • Rejects non-digits and updates live OTP stringTyping letters ignores them; digits update otp-value
  • Distributes pasted 6-digit OTP across all inputsPaste event fills every input cleanly
solution.html
Live Sandboxed Previewiframe sandbox
Starter template loaded — add your <script> logic in the editor (or open Reference Solution) to make the widget interactive.