1、判断字符串是否为连续的中文字符(不包含英文及其他任何符号和数字):
Regex.IsMatch("中文","^[\u4e00-\u9fa5]+$");
2、判断字符串是否为中文字符串(仅不包含英文但可以包含其他符号及数字):
!Regex.IsMatch("中文",@"[a-zA-Z]");
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string[] partNumbers= { "1298-673-4192","A08Z-931-468A",
"_A90-123-129X","12345-KKA-1230",
"0919-2893-1256" };
string pattern = @"^[a-zA-Z0-9]\d{2}[a-zA-Z0-9](-\d{3}){2}[A-Za-z0-9]$";
foreach (string partNumber in partNumbers)
Console.WriteLine("{0} {1} a valid part number.",
partNumber,
Regex.IsMatch(partNumber,pattern) ? "is" : "is not");
}
}
// The example displays the following output:
// 1298-673-4192 is a valid part number.
// A08Z-931-468A is a valid part number.
// _A90-123-129X is not a valid part number.
// 12345-KKA-1230 is not a valid part number.
// 0919-2893-1256 is not a valid part number.