("body"); function checkKey(key) { if (key != 9 && (key < 48 || key > 57)) { return false; } return true; } function goToNextInput(e) { var key = e.which, t =
(e.target).select(); } body.on("keyup", ".otp-field", goToNextInput); body.on("keydown", ".otp-field", onKeyDown); body.on("click", ".otp-field", onFocus); });
input{ width: 5rem; text-align: center; }<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="number" class="otp-field" maxLength="1" size="1" min="0" max="9" pattern="[0-9]{1}" name="otp[]" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" /> <input type="number" class="otp-field" maxLength="1" size="1" min="0" max="9" pattern="[0-9]{1}" name="otp[]" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" /> <input type="number" class="otp-field" maxLength="1" size="1" min="0" max="9" pattern="[0-9]{1}" name="otp[]" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" /> <input type="number" class="otp-field" maxLength="1" size="1" min="0" max="9" pattern="[0-9]{1}" name="otp[]" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" />
I have the following function which allows only number and excludes everything else when the user provides an input. However, this function is also blocking backspace and I am not being able to delete the number typed.
('body'); function goToNextInput(e) { var key = e.which, t =
(e.target).select(); } body.on('keyup', '.otp-field', goToNextInput); body.on('keydown', '.otp-field', onKeyDown); body.on('click', '.otp-field', onFocus); })
Here on line
if (key != 9 && (key < 48 || key > 57))
key != 9 OR key != 8
Anonymous Asked question May 14, 2021
Recent Comments