I searched for a solution for more than three days. I found one stack answer Stack Ans and his JSFiddle JSFiddle which is 100% working for Desktop and 99% working for the mobile version. Sample Code:
<input type="text" class="numeric" />
$('.numeric').on('input', function (event) {
this.value = this.value.replace(/[^0-9]/g, '');
});
View the jsfiddle link in mobile and test it for yourself,
Test case: provide input value as 12345
, then press spacebar twice
it removes 5
, next twice space key removes 4
. How to solve this?
The below code works in the Desktop browser and not in the mobile browser because the key code is not recognized.
$(".numeric").on("keypress", function (event) {
if ((event.which < 48 || event.which > 57)) event.preventDefault();
});
Test Video Log: Video Log Bug Report