I have seen lot of people asking how they can restrict users to numeric input only, so i thought to post it here as well.
well for making a text box to accept only numeric input, we will write a very simple javascript function in the <head></head> section of our markup like this.
-
<script type="text/javascript">
-
-
-
function isNumberKey(evt)
-
{
-
var charCode = (evt.which) ? evt.which : event.keyCode
-
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
-
alert("Please Enter Only Numeric Value:");
-
return false;
-
}
-
-
return true;
-
}
-
-
</script>
-
and on the TextBox which needs to be only numeric will have a markup like this
-
<asp:TextBox ID ="txtNumericInput" onkeypress="return isNumberKey(event)" runat ="server" ></asp:TextBox>
-
now run your project and try typing values other than numbers, you will get an alert..
Addan