dsdtumf776629385 2017-09-28 06:32
浏览 31
已采纳

Laravel:检查电子邮件服务提供商域及其子域

I wants restrict user to not to add some popular email service provider domain like gmail.com, yahoo.com, ymail.com, hotmail.com

for that I have created an array

$invalidDomain = ['gmail.com', 'yahoo.com', 'ymail.com', 'hotmail.com']

and then check user input with in_array

if(in_array($insertDomain, $invalidDomain)){
 //restrict
}

but now I also want to check for gmail.co.in, hotmail.co.uk

how can I?

  • 写回答

3条回答 默认 最新

  • dongsheng8664 2017-09-28 06:56
    关注

    You can use regular expressions to achieve this - it will give you more flexibility eg: if you would like to exclude gmail.co.uk but allow gmail.com. See the code snippet below:

    $insertDomain = "gmail.com";
    $invalidDomain = ['gmail\.[a-zA-Z\.]{2,}', 'yahoo\.[a-zA-Z\.]{2,}', 'ymail\.[a-zA-Z\.]{2,}', 'hotmail\.[a-zA-Z\.]{2,}'];
    
    // join regexp
    if (preg_match('/^'.implode("$|^", $invalidDomain).'$/', $insertDomain)) {
        // restrict
        echo $insertDomain."
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。