zoukankan      html  css  js  c++  java
  • 检测并替换用户输入的恶意字符

     /// <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;
            }
  • 相关阅读:
    正则表达式获取远程网页
    Devexpress 常见问题
    CSS 带显示隐藏左部页面按钮
    CSS 技巧积累
    SQL 常用操作
    重置 自增字段 起始值 和 步长
    Devexpress TreeList
    Devexpress GridControl
    JS常用
    ajax跨域请求
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/2001540.html
Copyright © 2011-2022 走看看