此方法用于确认用户输入的不是恶意信息

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

参照petshop 4.0

/// <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);

//将网页中非法和有攻击性的符号替换掉,以防sql注入!返回正常数据

text = Regex.Replace(text, "[\\s]{2,}", " "); // 2个或以上的空格

text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br> html换行符

text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); //&nbsp; html空格符

text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); // 任何其他的标签

text = text.Replace("'", "''");// 单引号

return text;

}

http://www.cnblogs.com/wang123/archive/2007/01/16/622035.html

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航