我想把Email中如下格式的定为非法如:“@-”(例:[email protected])
下面是现在用的验证Email的正则表达式:Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
请大家帮忙改改谢谢!!

解决方案 »

  1.   

    只是@后不能为-  ?@"^([\w-\.]+)@(?!-)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
      

  2.   

    string sourceString = @"[email protected]";
    string pattern = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([^-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
    System.Text.RegularExpressions.Match result = Regex.Match(sourceString,pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase);

    if (result.Success)
    {
    //提示正确信息
    //WL("正确:" + result.Groups[1].Value);//输出
    WL("正确:" + result.Value);//输出
    }
    else
    {
    //提示错误信息
    WL("错误!");//输出
    }
      
    -------------------------------------------
    MSN:[email protected] 
    请给我与您交流的机会
      

  3.   

    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
      

  4.   

    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
      

  5.   

    我现在用这个:
    return Regex.IsMatch(strIn, @"^([\w-\.]+)@(?!-)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");