<html>
<script>
function doCheck(txtidval)
{
var i,exceptions=[8,46,37,39,13,9]; // backspace, delete, arrowleft & right, enter, tab
var isException=false;
var isDot=(190==event.keyCode); // dot
//Value which is typed
var k=String.fromCharCode(event.keyCode);

for (i=0;i<exceptions.length;i++)
{
if(exceptions[i]==event.keyCode)
isException=true;
}

if(isNaN(k) && (!isException) && (!isDot))
{
event.returnValue=false;
}
else
{
var p=new String(document.getElementById(txtidval).value+k).indexOf(".");


if((p<document.getElementById(txtidval).value.length-2 || isDot) && p>-1 && (!isException))
{
event.returnValue=false;
}
else if(document.getElementById(txtidval).value.length>=3 && (!isException) && p==-1)
{
//dot checking
if(event.keyCode != "190")
{
alert(document.getElementById(txtidval).value);
event.returnValue=false;
}
}
else if(document.getElementById(txtidval).value>=3)
{
alert(document.getElementById(txtidval).value);
}
}
}
</script>
<body>
<input type="textbox" id="txtid" onkeydown="doCheck('txtid')"/>
</body>
</html>

i dont need output like .21 and also after entering 575 when moving curson in front of 575 it allows dot(".") so please kindly correct it