Text boxes that can only enter numbers and decimal places
HTML code
- <meta http-equiv= "Content-type" content= "text/html;charset=gb2312">
- <body>
- <!--Add the following code to <body> and </body>-->
- You can only enter a text box for numbers and decimals:<input onkeyup= "Value=value.replace (/[^d.] /g, ') '>
- </body>
>
<title>js can only enter numbers and decimal points </title>
<script language= "JavaScript" type= "Text/javascript">
function Clearnonum (obj)
{
First, replace the non-numeric, except for the numbers and.
Objobj.value = Obj.value.replace (/[^d.) /g, "");
The first one must be guaranteed to be number instead of.
Objobj.value = Obj.value.replace (/^./g, "");
Ensure that only one is present. and not multiple.
Objobj.value = Obj.value.replace (/.{ 2,}/g, ".");
Guaranteed. Occurs only once, and cannot appear more than two times
Objobj.value = Obj.value.replace (".", "$#$"). Replace (/./g, ""). Replace ("$#$", ".");
}
</script>
<body> <!--Add the following code to <body> and </body>--> Text boxes that can only enter numbers and decimals:<input id= "input1" onkeyup= "Clearnonum (This)"> </body>