<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <script type="text/javascript"> function AllowNumsOnly(evt) { var txt = document.getElementById('txt_Qty'); if (txt.value.length == 3) { txt.value = txt.value + '-'; } var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; else return true; } </script></head><body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txt_Qty" runat="server" onkeypress="return AllowNumsOnly(event);"></asp:TextBox> </div> </form></body></html>
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Javascript validations</title><script language="JavaScript" type="text/javascript">function NumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 47 && charCode < 58 || charCode == 127 || charCode == 8 || charCode == 45) { return true; } else { return false; }}</script> </head><body> <form id="form1" runat="server"> <div> Enter number<asp:TextBox ID="TextBox5" runat="server" onkeyPress="return NumberKey(event);"></asp:TextBox> </div> </form></body></html>
<SCRIPT language="JavaScript"> <!--function IsNumeric(strString) // check for valid numeric strings { var strValidChars = "0123456789.-"; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; } // --></SCRIPT>