Input Field accepting only numbers using javascript
R Arun Raj | Jun 17, 2008 | Comments 4
<input name=”demo” type=”text” id=”demo” onkeypress=”var unicode=event.keyCode? event.keyCode : event.charCode;if ((unicode < 32 || unicode > 33)&&(unicode < 45 || unicode > 57)) return false; return true;”>
This code compatible to all browsers !
Filed Under: javascript • Programming
About the Author: me : yeay its me arun




But this code is not working in FF
Sorry!!! its working now
the problem was in my side
Sorry Once again
Hi Arun,
In your code doesnot allows the back space key.So i rewrite the code as follows
function IsNumeric(event)
{
var unicode=event.keyCode? event.keyCode: event.charCode;
if ((unicode 33)&&(unicode 57) )
{
if(unicode==8)
{
return true;
}
return false;
}
return true;
}
Thanks
Thanks Kushal ..
Good job ..
-Arun