例如我判断一个字符串是不是全是数字组成的
JAVA很好搞的。C#的我真的很糊涂了。
string str = "中12";
            if (Regex.IsMatch(str,"\\d+"))
            {
                Label1.Text = "Yes";
            }
            else {
                Label1.Text = "No";
            }
这个出来居然是YES。我头大了啊

解决方案 »

  1.   

    应该是这样的:string str = "中12";
                if (Regex.IsMatch(str,"^\\d+$"))
                {
                    Label1.Text = "Yes";
                }
                else {
                    Label1.Text = "No";
                }
      

  2.   

    string str = "中12";
    if (Regex.IsMatch(str,@"^\d+$"))
    {
         Label1.Text = "Yes";
    }
    else
    {
          Label1.Text = "No";
    }建议有时间去看一下正则的参考资料Windows 脚本技术迷你小工具V1.0(正则测试+编码转换+IP转换)