此方法用于确认用户输入的不是恶意信息
点击次数:11 次 发布日期:2008-11-26 11:34:59 作者:源代码网
|
源代码网推荐 /// <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)*?>)", " "); //<br> html换行符 源代码网推荐 text = Regex.Replace(text, "(\s*&[n|N][b|B][s|S][p|P];\s*)+", " "); // html空格符 源代码网推荐 text = Regex.Replace(text, "<(.|\n)*?>", string.Empty); // 任何其他的标签 源代码网推荐 text = text.Replace(""", """");// 单引号 源代码网推荐 return text; 源代码网推荐 } 源代码网推荐 http://www.cnblogs.com/wang123/archive/2007/01/16/622035.html 源代码网推荐 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
