HTML5 the new number input type will call up the numeric keypad when the input box has the focus, increasing the effect of the experience. However, on some Android machines, you can switch the word input, and users will accidentally enter non-numeric characters such as "+" and "-". After testing, the number type automatically ignores alphabetic characters and other non-numeric characters, except for "+" "-" ". These two characters can be entered, because these two are symbols of positive and negative numbers and decimal points.
The number type also has a pit point where the value of the corresponding DOM element is null ("") if the contents of the input box are not pure digits (positive, negative numbers are OK), and the contents contain some characters.
So either the native document.getElementById ("TXT"). Value or JQ's $ (' selector '). Val () is empty.
This problem is difficult to solve, even the KeyUp and keypress listening input boxes will be met.
My requirement is that you cannot enter a decimal, that is, you cannot enter a character other than a number. The character is deleted after the input.
My practice is to use regular expressions to detect input characters and remove the last character. Monitor with KeyUp.
Keyup/keypress monitoring is not perceptible at the moment of entering a decimal point or +--the value of the DOM does not change. You can tell by value when you enter a numeric character after the symbol.
$ ("#moneyInput"). On ("KeyUp", function (e) {
var obj = $ ("#moneyInput"),
Value = Obj.val ();
if (! ( /(^\+? [1-9] [0-9]*$)/.test (value)) {
Value = value.substring (0,value.length-1);
Obj.val ("");
Obj.val (value);
}
});
HTML5 Input[number] Type input non-numeric character Val () to "" and solution