using System;
using System.Text;
namespace Sp.Common
{
public class ValidatorHelper
{
/// <summary>
/// 验证字符串字节数长度范围
/// [若要验证固定长度,可传入相同的两个长度数值;每个汉字为两个字节长度]
/// </summary>
/// <param name="input">待验证的字符串</param>
/// <param name="lengthBegin">长度范围起始值(含)</param>
/// <param name="lengthEnd">长度范围结束值(含)</param>
/// <returns></returns>
public static bool IsStringByteLength(string input, int lengthBegin, int lengthEnd)
{
//int byteLength = Regex.Replace(input, @"[^x00-xff]", "ok").Length;
//if (byteLength >= lengthBegin && byteLength <= lengthEnd)
//{
// return true;
//}
//return false;
int byteLength = Encoding.Default.GetByteCount(input);
if (byteLength >= lengthBegin && byteLength <= lengthEnd)
return true;
else
return false;
}
}
}