Use the following code:
function AllowNumsOnly(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) { document.getElementById('spnError').innerHTML = 'Allows only numbers'; return false; } else { document.getElementById('spnError').innerHTML = ''; return true; } }
<style> #spnError {color:Red;font-size:11px;} </style>
<asp:TextBox ID="txt_Qty" runat="server" onkeypress="return AllowNumsOnly(event);"></asp:TextBox><span id="spnError"></span>
Tag: Allow only numbers in textbox using javascript,allow numbers only onkeypress
nice article but i have to show error msg also
ReplyDelete