如题

解决方案 »

  1.   

    没用过就去学下
    http://www.microsoft.com/china/msdn/library/webservices/asp.net/regexnet.mspx?pf=true
      

  2.   

    在textBox的KeyPress事件中写private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar <= 57 && e.KeyChar >= 48 || e.KeyChar == 46 || e.KeyChar == 8)
        {
            e.Handled = false;
        }
        else
        {
            e.Handled = true;
        }
    }
    作用为只可以在textBox中输入数字,小数点,和Tab键。
      

  3.   

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                string strText = (sender as TextBox).Text;
                //只能输入数字、退格和小数点
                if (!char.IsDigit(e.KeyChar) && e.KeyChar!= 8 && e.KeyChar!='.')
                    e.Handled = true;
                //最多只能有一个小数点
                if ((e.KeyChar == '.') && (strText.IndexOf('.') > -1))
                    e.Handled = true;
            }