I found a keyup error while creating a function that automatically add the thousand separator when typing in input. Everything works fine on desktop browser but error occurs when using it on mobile responsive. Below is the js code that I used:
$('input.number').keyup(function(event) {
if(event.which >= 37 && event.which <= 40) return;
$(this).val(function(index, value) {
return value.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",")
;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="number">
</input>
Example : I type 1000000 on computer browser and it shows exactly 1,000,000 but shows 100,010,000 on mobile responsive.
I found another code like this on Fiddle but same error. The phone I used to test is also Android OS version 7, The version of Chrome is 93.0.4577.62
So how to fix this error? Does anyone have any suggestions for me? Any suggestions are appreciated!
Thanks so much!