This article will introduce to you how to limit the input input box to only pure numbers in HTML. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
onkeyup = "value=value.replace(/[^\d]/g,'')"
Using theonkeyup
event, there is abug
, that is, in the Chinese input method state, enter directly after inputting Chinese characters , the letters
onchange = "value=value.replace(/[^\d]/g,'')"
will be input directly using theonchange
event. After inputting the content, the result will only be obtained wheninput
loses focus, and cannot be done while typing. The response
oninput = "value=value.replace(/[^\d]/g,'')"
uses theoninput
event, which perfectly solves the above two problems. There are no other problems in the test yet.
Recommended learning:html video tutorial
The above is the detailed content of How to limit HTML input box to only pure numbers. For more information, please follow other related articles on the PHP Chinese website!