我有一个textbox要用来输入身份证号码,如何限定只能输入数字和字母X呢?

解决方案 »

  1.   

    使用RegularExpressionValidator验证控件,绑定textbox,在validationExpretion中选择身份证就OK了.
      

  2.   

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                 //在這里寫代碼
            }
      

  3.   

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (textBox1.SelectionLength == 0)
                {
                    e.Handled = (e.KeyChar < '0' || e.KeyChar > '9' || textBox1.Text.Length > 17);
                    if (e.KeyChar == (Char)Keys.Back || e.KeyChar == 'X')
                    {
                        e.Handled = false;
                    }
                }
            }