if Windows Application : In the textbox event :
private void txtZip_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
if Web application :
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function CheckNumeric(e) {
if (window.event) // IE
{
if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) {
event.returnValue = false;
return false;
}
}
else { // Fire Fox
if ((e.which < 48 || e.which > 57) & e.which != 8) {
e.preventDefault();
return false;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="TextBox1" runat="server" onkeypress="CheckNumeric(event);"
xmlns:asp="#unknown"></asp:textbox>
</form>
</body></head>