private void txtquanwen_TextChanged(object sender, EventArgs e)
{
string putter = "[^%&',;=?$\x22]+";
if (!CheckIsFormat(putter, this.txtquanwen.Text))
{
if (txtquanwen.Text == "")
{
txtqwbeforevalue = "";
}
else
{
txtquanwen.Text = txtqwbeforevalue;
}
}
else
{
txtqwbeforevalue = this.txtquanwen.Text;
}
}
public static bool CheckIsFormat(string strRegex, string strValue)
{
if (strValue != null && strValue.Trim() != "")
{
Regex re = new Regex(strRegex);
if (re.IsMatch(strValue))
{
return true;
}
else
{
return false;
}
}
return false;
}
我这样写 文本框里键盘按下'的时候 就不没反应 这还可以 可是如果输入其他字符 比如f再输入'的时候 就能输入了 为什么会这样丫 是不是 验证是否含有^%&',;=?$\"等字符:"[^%&',;=?$\x22]+" 这个正则表达式 只能匹配纯特殊字符的文本 不能匹配字符串? 我不懂正则的原理 在线等答案
袄 是这样呀 嗯嗯 我回家试试
本回答被提问者采纳