I will suggest two events on input box.
This will work on desktop webbrowser.
1) onkeypress = return isNumberKey(event);
function isNumberKey(e)
{
var evt = e || window.event;
if(evt)
{
var charCode = evt.keyCode || evt.which;
}
else
{
return true;
}
if((charCode > 47 && charCode < 58) || charCode == 9 || charCode == 8 || charCode ==46 || charCode ==37 || charCode==39)
{
return true;
}
return false;
}
This will work for mobile
2) onkeyup="numberMobile(event);"
function numberMobile(e){
e.target.value = e.target.value.replace(/[^\d]/g,'');
return false;
}
Apply both event on the input box and it will work.Only drawback is,It make it slow.But for now we have to live with it.
There is one issue woth this solution.Left navigation is not working.I will update more appropriate solution soon.
motorola moto g
with version4.4.2
– Brottkeypress
events all the time. Useinput
event, it is reliable. – Exhibitkeycode
not working.can you check thehttp://jsfiddle.net/33Snz/14/
.gettingundefined
– Brotthttp://stackoverflow.com/questions/22503559/backspace-not-firing-the-keyup-event-in-android-mobile
. – Brott