Web Hosting Talk







View Full Version : input numbers only + .


Duke of Lion
11-14-2006, 09:52 AM
onkeyup="this.value=this.value.replace(/[^0-9] /g,'')";

Hi guys, hope you can help me out with this one, I am using the code below to let the user only input numbers, thing is he must be able to add dots as wel like 9.99
somehow adding the dot and / or escaping it won't work, any ideas?

onkeyup="this.value=this.value.replace(/[^0-9.] /g,'')";

onkeyup="this.value=this.value.replace(/[^0-9\.] /g,'')";

Duke of Lion
11-14-2006, 03:20 PM
Solved....
maybe should be asking myself any questions anymore.......

<html>
<head>
<script>
function checkifnumber(valueToCheck)
{
if(isNaN(valueToCheck))
{
while(isNaN(valueToCheck))
{
valueToCheck= valueToCheck.substr(0,valueToCheck.length-1);
}
return valueToCheck;
}
else
{
return valueToCheck;
}
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="name1" onkeyup="this.value=checkifnumber(this.value)" >
</form>
</body>
</html>