正则表达式
public bool RegexName(string str)
{
bool res = false;
Regex reg = new Regex("^[a-zA-Z_0-9]+$");
if (reg.IsMatch(str))
{
res = true;
}
return res;
}
winform中文本框限制只能输入数字和字母、退格键
private void txtSN_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z')
|| (e.KeyChar >= '0' && e.KeyChar <= '9')
|| (e.KeyChar == 8) )
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
最后
以上就是明亮月饼最近收集整理的关于winform中文本框限制只能输入数字和字母,退格键的全部内容,更多相关winform中文本框限制只能输入数字和字母内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复