Now there is a demand for the following figure:
Product manager said card number can only let input numbers (the middle of the space is the format of the added, but also with JS), sometimes my mind appeared a voice, what things, add a type=number not on the line, the fact that the pattern Tucson broken, not to say type= Number will be followed by a subscript (although using CSS to kill), but this type is to support the scientific input method, is the decimal point and e Such is can input, so can only be used in other ways, and then want to use to retrieve the input is not a number to kill, but this can still input, the idea was called back, The final adoption of the keyboard input control method, in fact very simple, the code is as follows:
var isnumber=function (keycode) {
//digital
if (keycode >= && keycode <=) {return
true;
}
//Small numeric keypad
if (keycode >= && keycode <=) {return
true;
}
Tab Backspace, Del, left and RIGHT arrow keys
if (keycode = = 9| | KeyCode = = 8| | KeyCode = 32 | | keycode = 46 | | keycode = 37 | | KeyCode = =) {return
true;
}
return False
}
The so-called keyboard input control is based on the keyboard input of the keycode to determine what type of input, that is, to get the keyboard keys in the key to Unicode value, the keyboard on each key corresponding to the keycode is fixed, there are many tables on the Internet, I do not put up here, Each button to monitor the corresponding keycode and then check whether it is legitimate, it is necessary to note that here is not only the legal number, there are up and down the tab and Space direction key, can not disable the user's operation instructions, how, looks very simple.