LaVOZs

The World’s Largest Online Community for Developers

'; javascript - Can you prevent entering of 'periods' or 'dots' in a numbers input field on an Android webView using jQuery? - LavOzs.Com

I have a javascript application loaded into an Android webView. I have a table on the screen with items and next to the items are input fields where users enter their received quantities. We don't want people to use decimals but only whole numbers.

Is there a way to do this in an Android webview? All the special characters are showing a code or 229. I really want to prevent [.][,][-][ ] Right now I am trying:

$(document).on("keyup", "tr", ".rtqy-input", function(e) {
    var code = e.keyCode || e.which || e.charCode;
    toastr.info(code);
            if(code == 229){
                console.log(e);
                return false; 
            }
        return true;
    }
});

I'm not really able to get anything to happen.

I appreciate any help!

Not sure for Android Webview and its' keyCode, but when you want to prevent user from inputting character in input field with Javascript, you need to use 'keydown' event instead of 'keyup' event. Try changing event parameter in your on() function.

Related
Obtain form input fields using jQuery?
Detect the Enter key in a text input field
Taming JQuery Dialog Widget
How to send Keyboard events (e.g. Backspace, Delete) in Safari from Javascript
How to handle floats and decimal separators with html5 input type number
Android WebView enters unrecoverable state if executed JavaScript enters infinite loop
How to allow only integer value in input field for mobile application
Prevent decimal place being entered into input field on mobile