This allows only numeric (either whole or decimal) values in ASP Textbox control using JavaScript using ASP textbox key down event to fire the JavaScript function.
Example
<asp:TextBox ID="txtDaysOutLB" Text="" MaxLength="4" onkeydown="return jsDecimals(event);" Width="75px" runat="server"></asp:TextBox>
Javascript Function
function jsDecimals(e) {
var evt = (e) ? e : window.event;
var key = (evt.keyCode) ? evt.keyCode : evt.which;
if (key != null) {
key = parseInt(key, 10);
if ((key < 48 || key > 57) && (key < 96 || key > 105)) {
if (!jsIsUserFriendlyChar(key, "Decimals")) {
return false;
}
}
else {
if (evt.shiftKey) {
return false;
}
}
}
return true;
}
function jsIsUserFriendlyChar(val, step) {
if (val == 8 || val == 9 || val == 13 || val == 45 || val == 46) {
return true;
}
if ((val > 16 && val < 21) || (val > 34 && val < 41)) {
return true;
}
if (step == "Decimals") {
if (val == 190 || val == 110) {
return true;
}
}
return false;
}