javascript - Jquery preventDefault not working on android 4.4 default browser -


i working angular , jquery based website. have text input field validating array of floating numbers. requirement restrict user entering alphabets, etc.

the problem using e.preventdefault() not working in android default browser working in android chrome.

i have searched lot unable solution.

my sample code :-

 $('#test').keydown(function (e) {       e.stoppropagation();       e.preventdefault();       e.returnvalue = false;       e.cancelbubble = true;       return false; }); 

i have tried :-

$('#test').keydown(function (e) {   if (e.preventdefault) {        e.preventdefault();     } else {        e.returnvalue = false;   } }); 

working fiddle

note:- cannot use keypress event android default browser cannot listen event.

i had problem default browser on android. preventdefault didn't me, used .on jquery function.

    $('#test').on('input',function () {         var inputtext = $(this).val();          var resulttext = inputtext.replace(/[^0-9]/g, '');         $(this).val(resulttext);     }); 

you can add regex other characters need allowed. hope helps.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -