/// <summary>
/// 过滤无效输入字符
/// </summary>
/// <param name="text">原字符串</param>
/// <param name="maxLength">最大长度,多余将被截除</param>
/// <returns>过滤后的字符串</returns>
public static string InputText(string text, int maxLength)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxLength)
text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[//s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|//n)*?>)", "/n"); //<br>
text = Regex.Replace(text, "( //s*&[n|N][b|B][s|S][p|P];//s*)+", " "); //
text = Regex.Replace(text, "<(.|//n)*?>", string.Empty); //any other tags
text = text.Replace("'", "''");
return text;
}
/// 过滤无效输入字符
/// </summary>
/// <param name="text">原字符串</param>
/// <param name="maxLength">最大长度,多余将被截除</param>
/// <returns>过滤后的字符串</returns>
public static string InputText(string text, int maxLength)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxLength)
text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[//s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|//n)*?>)", "/n"); //<br>
text = Regex.Replace(text, "( //s*&[n|N][b|B][s|S][p|P];//s*)+", " "); //
text = Regex.Replace(text, "<(.|//n)*?>", string.Empty); //any other tags
text = text.Replace("'", "''");
return text;
}