if (theStr!= null)//注意加非空判断,否则报错
{ System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^d+$");//^开始,d匹配一个数字字符,+出现至少一次,$结尾 if (rex.IsMatch(theStr)) { }
}