Azaz wrote:hi all
i have a text box for quantity. i want to restrict users to put only numeric data not alphabet ( a-z ).
any idea how to do that???
hi
lets say you have a text box of name "Qty" as below;
Code:
<asp:TextBox ID="Qty" runat="server" MaxLength="5" Width="30px" ></asp:TextBox>
and you write this line in page load event
Code:
Qty.Attributes.Add("onkeypress","return isNumberKey(event)");
then on aspx you copy and past following javascript function.
Code:
<script language="javascript" type="text/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) )
return false;
return true;
}
</script>
i have tried it works. i hope that will solve your problem!
Happy Coding