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

Tutorial on installing the unpacked version of mysql5.7 on CentOS 7

1. Unzip the mysql compressed package to the /usr...

A brief analysis of the basic concepts of HTML web pages

What is a web page? The page displayed after the ...

Detailed explanation of CocosCreator Huarongdao digital puzzle

Table of contents Preface text 1. Panel 2. Huaron...

vue-amap installation and usage steps

I have previously shared the usage of asynchronou...

Summary of important mysql log files

Author: Ding Yi Source: https://chengxuzhixin.com...

Introduction to generating Kubernetes certificates using OpenSSL

Kubernetes supports three types of authentication...

VMware configuration hadoop to achieve pseudo-distributed graphic tutorial

1. Experimental Environment serial number project...

Nginx builds rtmp live server implementation code

1. Create a new rtmp directory in the nginx sourc...

How to implement the singleton pattern in Javascript

Table of contents Overview Code Implementation Si...

Detailed explanation of galera-cluster deployment in cluster mode of MySQL

Table of contents 1: Introduction to galera-clust...

Detailed explanation of the new array methods in JavaScript es6

Table of contents 1. forEach() 2. arr.filter() 3....