在网上找的一段代码
private const string StrKeyWord = @"select|insert|delete|from|count(|drop table|update|truncate|asc(|mid(|char(|xp_cmdshell|exec master|netlocalgroup|administrators|:|net user|""|or|and";
    private const string StrRegex = @"[-|;|,|/|(|)|[|]|}|{|%|@|*|!|']";
public static bool CheckKeyWord(string _sWord)
    {
        if (Regex.IsMatch(_sWord, StrKeyWord, RegexOptions.IgnoreCase) || Regex.IsMatch(_sWord, StrRegex))
            return true;
        return false;
    }错误一:正在分析“select|insert|delete|from|count(|drop table|update|truncate|asc(|mid(|char(|xp_cmdshell|exec master|netlocalgroup|administrators|:|net user|"|or|and”- ) 不足。错误二:正在分析“[-|;|,|/|(|)|[|]|}|{|%|@|*|!|']”- 限定符 {x,y} 前没有任何内容。
请帮我解解!

解决方案 »

  1.   

    protected bool IsDanger(string InText)
    {
        string word = @"exec|insert|select|delete|update|master|truncate|char|declare|join|
    iframe|href|script|<|>|request";
        if (InText == null)
            return false;
        if (Regex.IsMatch(InText,word))
             return true;
         return false;
      

  2.   


    private const string StrKeyWord = @"select|insert|delete|from|count\(|drop table|update|truncate|asc\(|mid\(|char\(|xp_cmdshell|exec master|netlocalgroup|administrators|:|net user|""|or|and";
    private const string StrRegex = @"[-;,/()[\]}{%@*!']";