Enter a six-digit code and click Check code. For this demonstration only, 123456 is considered valid.
JavaScript
const wrapper = document.querySelector('#otpValidationWrapper');
const otp = bootstrap.OtpInput.getOrCreateInstance(wrapper);
document.querySelector('#otpDemoForm').addEventListener('submit', event => {
event.preventDefault();
const value = otp.getValue();
if (value.length !== 6) {
wrapper.classList.remove('is-valid');
wrapper.classList.add('is-invalid');
// Show an error message.
return;
}
// Send value to your server to verify the real OTP.
console.log('OTP entered:', value);
});
The demo compares against a sample value in browser code only. Never use a client-side comparison as real OTP security.