c# 怎样控制textbox不能输入数字?

解决方案 »

  1.   

    本帖最后由 caozhy 于 2011-10-13 00:38:14 编辑
      

  2.   

        <asp:TextBox ID="TextBox1" onKeyPress="ValNum()" runat="server"></asp:TextBox>
        <script>
            function ValNum() {
                if (window.event.keyCode >= 48 && window.event.keyCode <= 58) {
                    window.event.keyCode = 0;
                }
            }
        </script>
      

  3.   


    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
       if (char.IsDigit(e.KeyChar))//判断Unicode字符是否属于十进制数字类别
           e.Handled = true;
    }