限制字符的键盘异常

时间:2015-05-16 13:06:18

标签: c# keypress

如何在仅限于数字的文本框中使用空格键?

 private void CLimitTxt_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!char.IsNumber(e.KeyChar))
        {
            MessageBox.Show("You can only enter numbers within this textbox", "Error");
            CLimitTxt.Text = "";
            e.Handled = true;
        }
    }

我是否需要声明带有异常的var regex?

1 个答案:

答案 0 :(得分:2)

就这么简单:

>>> "land" in "motherland"
True
>>> "banana" in "motherland"
False