Where should the paste fill start in an OTP input?
From the current focused input's index, not always from the first. If the user pastes into the third input, fill from index 2: inputs[index + i].value = char. This matches user expectation.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in OTP Input Paste Support Implementation in JavaScript
Listen for the paste event, prevent default, get the pasted text from clipboardData, filter to numeric only with replace(/\D/g, ''), split into characters, and fill each input starting from the current index. Focus the last filled input and check completion.
Because the default paste would fill only the current input with the entire pasted string (which exceeds maxlength=1, so only the first character is kept). preventDefault lets you control how the pasted text is distributed across the inputs.
Check if index + i < inputs.length before filling each input: if (index + i < inputs.length) inputs[index + i].value = char. Extra characters are ignored. Focus the last input: Math.min(index + pasted.length, inputs.length - 1).
Still have questions?
Browse all our FAQs or reach out to our support team
