I am trying to create an input field in my form that only accepts numbers when pasted into it.
For example: If I have some random characters like W123W000 on my clipboard, the input field should only paste 123000.
Note: This solution is currently only functional in Chrome browser.
I have been exploring possible solutions online and have found the following code snippet. However, it does not seem to be working as intended.
var inputBox = document.getElementsByClassName('numbersOnly');
inputBox.onchange = function () {
inputBox.value = inputBox.value.replace(/[^0-9]/g, '');
}
<input id="number" type="number" class="numbersOnly">