zoukankan      html  css  js  c++  java
  • .net中 过滤 指定 字符串


            /// <summary>
            /// 过滤字符
            /// </summary>
            /// <param name="Input"></param>
            /// <returns></returns>
            public static string Filter(string sInput)
            {
                if (sInput == null || sInput == "")
                    return null;
                string sInput1 = sInput.ToLower();
                string output = sInput;
                string pattern = @"*|and|exec|insert|select|delete|update|count|master|truncate|declare|char(|mid(|chr(|'";
                if (Regex.Match(sInput1, Regex.Escape(pattern), RegexOptions.Compiled | RegexOptions.IgnoreCase).Success)
                {
                    throw new Exception("字符串中含有非法字符!");
                }
                else
                {
                    output = output.Replace("'", "''");
                }
                return output;
            }
  • 相关阅读:
    聊天工具分享bug
    Git命令查看代码提交次数
    短链接生成实例
    .Net MVC用户注册验证码
    js写验证码
    笔记
    jq获取数组中的某个字段拆分成字符串。
    IIS部署后中文Cookie乱码
    C#反射(Reflection)与特性(Attribute)实例
    jmm
  • 原文地址:https://www.cnblogs.com/mahaisong/p/1964896.html
Copyright © 2011-2022 走看看