"."/> ".">

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

How to input only numbers in html input

青灯夜游
青灯夜游Original
2021-05-13 11:42:029534browse

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;)">

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

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn