Home>Article>Web Front-end> How to restrict HTML input box to only input pure numbers

How to restrict HTML input box to only input pure numbers

醉折花枝作酒筹
醉折花枝作酒筹 Original
2021-04-07 18:33:59 8478browse

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.

How to restrict HTML input box to only input pure numbers

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!

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