加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

正则表达式限制文本框不能输入特殊字符

(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;
        }

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有