validateInt() allows only the integer values to the textbox.
function validateInt(key) {
var keycode = (key.which) ? key.which : key.keyCode;
if ((keycode != 8) && (keycode < 48 || keycode > 57)) {
return false;
}
else {
return true;
}
}
validateDec() allows Decimal values and it allows only one decimal point.
function validateDec(key) {
var keycode = (key.which) ? key.which : key.keyCode;
if (!(keycode == 8 || keycode == 46) && (keycode < 48 || keycode > 57)) {
return false;
}
else {
var parts = key.srcElement.value.split('.');
if (parts.length > 1 && keycode == 46)
return false;
return true;
}
}
And call the above required method from your textbox
keypress event like below.
<asp:TextBox ID="txtDays" runat="server" onkeypress="return validateInt(event)" />
<asp:TextBox ID="txtCost" runat="server" onkeypress="return validateDec(event)" />