用于登录页面上判断用户名/密码中是否含有这个符号~ 谢谢同志们了~

解决方案 »

  1.   


    /// <summary>
    /// 验证注册用户名是否合法
    /// </summary>
    public static bool NameIsDisallowed(string name)
    {
    //判断是否含有非法字符!@#$%^.......
    if(name != Regex.Replace(name,@"[^\w]",""))
    return true;string regExWildcard = "+\\S*";
    ArrayList bannedNames = GetNames();//不允许使用的字符ArrayList
    if(bannedNames == null)
    return false;
    bool found = false;
    RegexOptions regExOpt = RegexOptions.IgnoreCase;IEnumerator tmpEnum = bannedNames.GetEnumerator();
    while( tmpEnum.MoveNext() ) 
    {
    string thePattern = @"^" + tmpEnum.Current.ToString().Replace("*", regExWildcard) + @"$";
    Regex regEx = new Regex(thePattern, regExOpt);
    if( regEx.IsMatch(name) == true ) 
    {
    found = true;
    break;
    }
    }
    return found;
    }
    static ArrayList GetNames()
    {
    ArrayList arr = new ArrayList();
    //foreach(string s in ("'").Split(','))
    foreach(string s in SiteSettings.RegisterCensorship.Split(',')){
    if(s.Trim() != string.Empty)
    arr.Add(s.Trim());
    }
    return arr;
    }
      

  2.   

    就判断这一个符号还用正则阿?直接indexof不就行乐?