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.