日期:2014-05-19  浏览次数:20815 次

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

------解决方案--------------------
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;
}
}
}