C# 正则校验

1、字符串为小写字母:

string pattern = @"^[a-z]*$";

if(System.Text.RegularExpressions.Regex.IsMatch("校验字符串", pattern)){
    "校验通过";      
}

2、字符串为汉字

if (Regex.IsMatch("校验字符串", @"^[u4e00-u9fa5]+$")) {
    "校验通过";
}

3、字符串为数字

if(Regex.IsMatch("校验字符串", @"^[0-9]+$")){
    "校验通过";   
}
原文地址:https://www.cnblogs.com/MichaelWillLee/p/6936291.html