Home>Article>Web Front-end> How to restrict HTML input box to only input pure numbers
Method to limit the input input box to only pure numbers: through the oninput event, use the replace() function in the event with the regular expression "/[^\d]/g,''" to limit the input. Achieve the effect that only numbers can be entered in the input text box, and other characters will be automatically cleared when entering other characters.
The operating environment of this tutorial: windows7 system, javascript1.8.5&&HTML5 version, Dell G3 computer.
Restrict the input input box to only input pure numbers
Use the oninput event,Restrict the input input box to only input pure numbers
oninput = "value=value.replace(/[^\d]/g,'')"
Code Example
input 只能输入纯数字的输入框:
Recommended study: "HTML Video Tutorial"
The above is the detailed content of How to restrict HTML input box to only input pure numbers. For more information, please follow other related articles on the PHP Chinese website!