"."/> ".">
Home > Article > Web Front-end > How to input only numbers in html input
Input can only input numbers: Use the oninput attribute in the input tag with a regular expression to add an input restriction event. The syntax format is "".
The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.
Add in the input tagoninput = "value=value.replace(/[^\ d]/g,'')"
Code is enough
Example:
<input type="text" oninput = "value=value.replace(/[^\d]/g,'')">
Rendering
Description:
The oninput event is triggered when the user inputs.
This event is triggered when the value of the or
HTML:
<element oninput="myScript">
JavaScript:
object.oninput=function(){myScript};
Recommended tutorial: "html video tutorial"
The above is the detailed content of How to input only numbers in html input. For more information, please follow other related articles on the PHP Chinese website!