【问题标题】:What the Error in my Regex to to check a string contains a-z or A-Z我的正则表达式中检查字符串的错误包含 a-z 或 A-Z
【发布时间】:2013-08-18 13:53:42
【问题描述】:

这是我的代码,用于检查字符串是否包含除 a-z 或 A-Z 之外的任何其他字符。

        Regex  pattern = new Regex("^[a-zA-Z]+$");
        if (pattern.IsMatch(txtCustName.Text))
        {

            MessageBox.Show("Name contains some Invalid Characters");

            txtCustName.Focus();
        }

即使我输入正确的字符串,它仍然显示错误消息。

【问题讨论】:

    标签: c# regex regex-negation


    【解决方案1】:

    正则表达式没问题。否定谓词:

    if (! pattern.IsMatch(txtCustName.Text))
    

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 2010-11-02
      • 2011-08-26
      • 2012-08-05
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 2019-12-10
      • 2015-05-26
      相关资源
      最近更新 更多