Text box can only enter numbers js code of with decimal point
- 2021-07-02 23:08:01
- OfStack
You can only enter more than 0-9 including decimal points
<html>
<head>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<title>js You can only enter numbers and decimal points </title>
<script language="JavaScript" type="text/javascript">
function clearNoNum(obj)
{
obj.value = obj.value.replace(/[^\d.]/g,""); // Clear "number" and " . Characters other than "
obj.value = obj.value.replace(/^\./g,""); // Verify the 1 Characters are numbers instead of .
obj.value = obj.value.replace(/\.{2,}/g,"."); // Keep only the 1 A . Clear the redundant .
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
</script>
</head>
<body>
Text boxes for which only numbers and decimal points can be entered: <input name="input1" onkeyup="clearNoNum(this)">
</body>
</html>