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
<!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>
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!