javascript function to restrict user to type only numbers in textbox.
Code:
<script type = "text/javascript" language = "javascript">
function numeralsOnly(evt)
{
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
{
alert("Enter numerals only in this field!");
return false;
}
return true;
}
</script>
the way in which it can be specified with a textbox inside a gridview:
<asp:TextBox ID="txtProjBudget" onkeypress="return numeralsOnly(event)" runat="server" Text='<%# Eval("Proj_Exp") %>' Width="103px"></asp:TextBox>
No comments:
Post a Comment