Introduction :
Hi, In this Example i will Code you how to Make TextBox to Allow only numbers as a Input. Previously i have Explained How to Make Textbox Readoly , Here it allows only Numbers. Here i have used keypress event of the TextBox and, keycode for user to enter the input. it usually used for float or decimal DataType.
Aspx and JavaScript :
Hi, In this Example i will Code you how to Make TextBox to Allow only numbers as a Input. Previously i have Explained How to Make Textbox Readoly , Here it allows only Numbers. Here i have used keypress event of the TextBox and, keycode for user to enter the input. it usually used for float or decimal DataType.
Aspx and JavaScript :
<html>
<head runat="server">
<title>FourthBottle.com</title>
<script type="text/javascript">
function
NumbersOnly(key)
{
var
keycode = (key.which) ? key.which : key.keyCode;
if
(!(keycode == 8 || keycode == 46) && (keycode < 48 || keycode >
57))
{
return
false;
}
else
{
return
true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt1" runat="server" onpaste="return false;" onkeypress="return NumbersOnly(event);" ></asp:TextBox>
</div>
</form>
</body>
</html>