Basicallly When we trying to validate a form some time we need numeric validation for textbox.
We can validate textbox by onkeypress event of the control By checking whether the keycode of the key pressed as the user types falls within the range of the number keys 48-57(i.e 0-9 and '.') ,if not belong to that range it will return false then it will disable the keypress action
function NumericValidation(eventObj)
{
var keycode;
if(eventObj.keyCode) //For IE
keycode = eventObj.keyCode;
else if(eventObj.Which)
keycode = eventObj.Which; // For FireFox
else
keycode = eventObj.charCode; // Other Browser
if (keycode!=8) //if the key is the backspace key
{
if (keycode<48||keycode>57) //if not a number
return false; // disable key press
else
return true; // enable key press
}
}
Thanks & Regards
Hari
Priti2010, if this helps please login to Mark As Answer. | Alert Moderator