Limit HTML text box input to only numbers and decimal points

Limit HTML text box input to only numbers and decimal points

Code:

<input type="text" class="txt" name="qty" value="" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')" />

PS: js implements a text box that can only input numbers and decimal points

<html><head><meta http-equiv="content-Type" content="text/html;charset=gb2312"><title>js can only input numbers and decimal points</title>
<script language="JavaScript" type="text/javascript">
function clearNoNum(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); //Clear characters other than "number" and "." obj.value = obj.value.replace(/^\./g,""); //Verify that the first character is a number and not a . 
  obj.value = obj.value.replace(/\.{2,}/g,"."); //Only keep the first one. Clear the rest.   
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");

}
</script>
</head><body>Text box that can only input numbers and decimal points: <input name="input1" onkeyup="clearNoNum(this)"></body></html>

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. At the same time, I also hope that you can support 123WORDPRESS.COM!

<<:  Detailed explanation of how two Node.js processes communicate

>>:  Let's talk about the performance of MySQL's COUNT(*)

Recommend

Detailed explanation of Vue's monitoring method case

Monitoring method in Vue watch Notice Name: You s...

Specific use of the wx.getUserProfile interface in the applet

Recently, WeChat Mini Program has proposed adjust...

Docker large-scale project containerization transformation

Virtualization and containerization are two inevi...

CocosCreator implements skill cooling effect

CocosCreator realizes skill CD effect There are s...

Detailed tutorial on installing MySQL 8.0.19 in zip version on win10

Table of contents 1. After downloading, unzip it ...

MySQL transaction, isolation level and lock usage example analysis

This article uses examples to describe MySQL tran...

JavaScript+html to implement front-end page sliding verification

This article shares the specific code of JavaScri...

A brief discussion on CSS cascading mechanism

Why does CSS have a cascading mechanism? Because ...

MySQL table type storage engine selection

Table of contents 1. View the storage engine of t...

Let's talk briefly about the changes in setup in vue3.0 sfc

Table of contents Preface Standard sfc writing me...

About the overlap of margin value and vertical margin in CSS

Margin of parallel boxes (overlap of double margi...

How to quickly clean up billions of data in MySQL database

Today I received a disk alarm exception. The 50G ...