drus40229 2011-07-01 12:53
浏览 73
已采纳

使用Regex阻止某些电子邮件提供商

Please dont downvote the question because of the fact that the answer Im looking for is not an anser someone should pursue. I'm fully aware of that, but it's not my idea, I just have to deliver :D

In cakephp, I have the following dataentry in my model:

    'email' => array(
        'email' => array(
            'rule' => array('email',false,'(^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$)')
        ),
    )

The email rule is a common function in cakephp data validation, and the second and third parameter are optional. The third being the regex. I wasnt happy with the given regex string so I added my own. Now I want to exclude Gmail, Hotmail and yahoo addresses.

How can I change the Regular Expression so those addresses are producing false as result? I cant get it right.

  • 写回答

2条回答 默认 最新

  • dthdlv9777 2011-07-01 13:06
    关注

    Why on earth would you want to exclude gmail, hotmail and yahoo addresses? There are plenty of people who only have one of these addresses and no other. This is a bad idea. If you are target a specific "audience" I'd suggest making a list of allowed domains instead.

    Anyway, here's a functional regex for you which is shorter than the one you already have.. try it out:

    \b[\w\.-]+@((?!gmail|googlemail|yahoo|hotmail).)[\w\.-]+\.\w{2,4}\b
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?