C# 只能输入字母或数字

c# 只能输入字母或者数字 或者退格符 git

方法一:KeyPress正则表达式

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar != '\b') &&(!Char.IsLetter(e.KeyChar)) && (!char.IsDigit(e.KeyChar)))
            {
                e.Handled = true;
            }

        }

 

 

 

 

方法二: 正则表达式c#

添加引用blog

using System;
using System.Text.RegularExpressions;it

相关文章
相关标签/搜索