正则表达式限制文本框不能输入特殊字符
(2012-05-07 15:42:17)
标签:
杂谈 |
2011-12-8 20:12
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;
}
前一篇:Picture 控件的绘制

加载中…