检测并替换用户输入的恶意字符

 /// <summary>
        /// 该方法检测并替换用户输入的恶意字符
        /// </summary>
        /// <param name="text">用户输入的文字 </param>        
        /// <returns>返回验证后的文字 </returns>
        public static string InputText(string text)
        {
            text = text.ToLower().Trim();
            if (string.IsNullOrEmpty(text))
            {
                return string.Empty;
            }
            else
            {
                text = Regex.Replace(text, ".", "。");
                //text = Regex.Replace(text, "=", "");
                //text = Regex.Replace(text, "%", "");
                text = Regex.Replace(text, "'", "’");
                //text = Regex.Replace(text, "select", "");
                //text = Regex.Replace(text, "insert", "");
                //text = Regex.Replace(text, "delete", "");
                //text = Regex.Replace(text, "or", "");              
                //text = Regex.Replace(text, "--", "");
                //text = Regex.Replace(text, "and", "");
                //text = Regex.Replace(text, "where", "");
                //text = Regex.Replace(text, "update", "");              
                //text = Regex.Replace(text, "master", "");
                //text = Regex.Replace(text, "exec", "");
                //text = Regex.Replace(text, " <", "");
                //text = Regex.Replace(text, ">", "");
            }
            return text;
        }
posted @ 2011-03-31 21:48  放哨De老鼠  阅读(265)  评论(0编辑  收藏  举报