limit input
input box can only enter pure Numbers
1, the onkeyup = "value, value = replace (/ [^ \] d/g,") " code> p>
USES the
onkeyup
event, and has thebug
, that is, in the state of Chinese input method, after Chinese characters are input, enter directly, the letterwill be input directly
2, onchange = "value, value = replace (/ [^ \] d/g,") " code> p>
USES the
onchange
event. After input content, only theinput
loses focus will get the result, and the responsecannot be made when input
3, the oninput = "value, value = replace (/ [^ \] d/g,") " code> p>
USES the
oninput
event, which perfectly solves the above two problems. There are no other problems in the test for the time being.
code example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>input</title>
</head>
<body>
只能输入纯数字的输入框:<input type="text" name="" oninput="value=value.replace(/[^\d]/g,'')">
</body>
</html>
above code has been tested in Google, firefox, baidu, UC, IE11, 360 fast, QQ, Edge browser, please feel free to use,
thanks for qq_38726717
, xiao xiao xin
feedback in the comments section.
Read More:
- Vue element El input search to achieve anti shake @ input event requests frequently
- How to increase the effect of onchange event after adding readonly attribute to input tag and display time of laydate plug-in
- How to Fix errors in Chinese input of latex
- How to use JavaScript in HTML
- How to center the box horizontally and vertically in HTML
- Assertion `input_val >= zero && input_val <= one` failed
- How to Split numbers and strings in a strings
- Nohup command in Linux: nohup: assigning input and attaching output to‘ nohup.out ’
- Android monitor EditText text input EditText monitor events and input events
- How to use dangerously set inner HTML in react
- To solve the problem of repeated password input when operating sourcetree on MAC
- Windows 7 system, start to run input CMD, the window flashed by, disappeared
- [Solved] Failed to set attribute: Invalid input data or parameter
- The solution to the sudden change of win10 input method into traditional Chinese
- Solution to sudden change of win10 input method into traditional Chinese
- iOS Failed to find matching arch for 64-bit Mach-O input file
- Float: 99: input / output error appears in vscode SSH plug-in
- Solve the problem that data cannot be input in idea console
- Ubuntu 16.04 install Chinese input method
- Solution of no input file specified. In local server Apache