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]+$")){
    "校验通过";   
}

 

posted @ 2017-06-03 09:36  Michael我想念你  阅读(267)  评论(0编辑  收藏  举报