Home > Web Front-end > HTML Tutorial > How to input only numbers in html input

How to input only numbers in html input

青灯夜游
Release: 2023-01-06 11:12:51
Original
9596 people have browsed it

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 "".

How to input only numbers in html input

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

html input tag requires that only pure numbers can be entered

Add in the input tagoninput = "value=value.replace(/[^\ d]/g,'')"Code is enough

Example:

<input type="text" oninput = "value=value.replace(/[^\d]/g,&#39;&#39;)">
Copy after login

Rendering

How to input only numbers in html input

Description:

The oninput event is triggered when the user inputs.

This event is triggered when the value of the or