<html>
<head>
<script language="javascript">
function blockChar()
{
var str = document.getElementById('txt').value;
str = str.replace(/[^\d]*/g,'');
document.getElementById('txt').value = str;
}
</script>
</head>
<body onload="javascript:document.getElementById('txt').focus();">
<input type="text" id='txt' onkeyup="blockChar();" />
</body>
</html>
Program Demo
Note:IE Supported
2 comments:
I want allow "12.39" i.e i want to allow decimal point how do i do that?
hi Pushkar Firodiya ,
if u want to decimal point meanse replace the current Reg Exp with the folloing one
str.replace(/[^\d.]*/g,'');
Post a Comment