OTP input
One box per character, for verification codes and PINs. It stays one real input under the hood, so phones can fill the code straight from the SMS, pasting "123 456" works, and your form sees a normal field.
<input class="form-control" name="code" data-moey-otp="6" required aria-label="Verification code">
<button type="button" class="btn btn-link" data-moey-countdown="30" data-moey-countdown-start>Resend code</button>
<script>
code.addEventListener('moey:complete', async (e) => {
const ok = await checkCode(e.detail.value);
code.classList.toggle('is-invalid', !ok); // red, with a little shake
});
</script>
- Typing moves along by itself; Backspace goes back; ← → move; click any box to change it.
- Letters and spaces are dropped from number codes, so a pasted "123-456" becomes
123456. - When every box is full it fires
moey:complete.data-moey-autosubmitsends the form right away. - It sets
inputmode="numeric",autocomplete="one-time-code",patternand the length for you — sorequiredmeans "all boxes filled".
Groups, PINs and letters
data-moey-separator="3" adds a dash every 3 boxes. data-moey-mask shows dots (for PINs). data-moey-otp-type="alphanumeric" allows letters too, shown in capitals — handy for backup and gift codes.
<input class="form-control" data-moey-otp="6" data-moey-separator="3" aria-label="Code">
<input class="form-control" data-moey-otp="4" data-moey-mask aria-label="PIN">
<input class="form-control" data-moey-otp="8" data-moey-separator="4" data-moey-otp-type="alphanumeric" aria-label="Backup code">
Sizes and filled
.otp-sm and .otp-lg on the input, and .form-filled for the borderless look. On phones the boxes shrink to fit.
<input class="form-control otp-sm" data-moey-otp="6">
<input class="form-control otp-lg form-filled" data-moey-otp="4">
Send it when it's full
data-moey-autosubmit submits the form as soon as the last digit is in — no button press needed. The button is still there for people who prefer it.
<form>
<input class="form-control" name="pin" data-moey-otp="4" data-moey-autosubmit aria-label="Door PIN">
</form>
Countdown buttons
Works on any button: after a click it waits (disabled) and shows the time left. data-moey-countdown-start waits right away; data-moey-countdown-text sets the waiting text.
<button class="btn" data-moey-countdown="10">Resend code</button>
<button class="btn" data-moey-countdown="15" data-moey-countdown-text="Try again in {time}">Send magic link</button>
<script>
Moey.countdown(button, 60); // start one from code
button.addEventListener('moey:countdown-end', …);
</script>
| Class / attribute | What it does |
|---|---|
data-moey-otp="6" | Boxes for a 6-character code (or use maxlength) |
data-moey-separator="3" | A dash after every 3 boxes |
data-moey-otp-type="alphanumeric" | Letters and numbers (shown in capitals) |
data-moey-mask | Dots instead of the characters |
data-moey-autosubmit | Send the form when it's full |
placeholder="000000" | A faint hint in each box |
.otp-sm · .otp-lg · .form-filled · .is-invalid | Sizes · borderless · wrong code (red, shakes) |
moey:complete | Every box filled (e.detail.value) |
data-moey-countdown="30" · -start · -text | A button that waits before it can be clicked again |