Tuesday, June 14, 2011

Only Numbers

Javascript textbox validation to allow only numbers, decimal and backspace


// Allow only backspace and delete and decimal 
if  (event .keyCode == 46 || event .keyCode == 8  || event .keyCode == 9||(event .keyCode==37)||
           (event .keyCode==39)) {
// let it happen,'t do anything 
}
else  {
// Ensure that it is a number and stop the keypress 
if  ((event .keyCode >= 48 && event .keyCode <= 57) ||(event .keyCode==110) ||(event .keyCode==190) || (event .keyCode >= 96 && event .keyCode <= 105)) {
}
else  {
event .preventDefault();
}
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More