判断是否汉字或数字或英文单词

// <summary>
/// 只读形式读取文件
/// </summary>
/// <param name="filePath"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static string ReadOnlyFileContent(string filePath, Encoding encoding)
{
if ( System.IO.File.Exists(filePath) )
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
byte[] buffer = new byte[ fs.Length ];
fs.Position = 0;
fs.Read(buffer, 0, buffer.Length);
return encoding.GetString(buffer);
}
else
{
return "";
}
}


/// <summary>
/// 判断是否汉字
/// </summary>
public static bool IsChinese(string value)
{
Regex rg = new Regex("^[u4e00-u9fa5]+$");
return rg.IsMatch(value);
}

/// <summary>
/// 判断是否数字
/// </summary>
public static bool IsNumber(string value)
{
Regex rg = new Regex("^[0-9]+$");
return rg.IsMatch(value);
}

/// <summary>
/// 判断是否字母
/// </summary>
public static bool IsWord(string value)
{
Regex rg = new Regex("^[a-zA-Z]+$");
return rg.IsMatch(value);
}

/// <summary>
/// 判断是否汉字或数字或英文单词
/// </summary>
public static bool IsChineseOrNumberOrWord(string value)
{
Regex rg = new Regex("^[u4e00-u9fa5a-zA-Z0-9]+$");
return rg.IsMatch(value);
}

原文地址:https://www.cnblogs.com/itclw/p/12421268.html