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条)

报告相同问题?

悬赏问题

  • ¥15 streamingtool
  • ¥15 MATLAB图像问题
  • ¥20 树莓派5做人脸情感识别与反馈系统
  • ¥15 selenium 控制 chrome-for-testing 在 Linux 环境下报错 SessionNotCreatedException
  • ¥15 使用pyodbc操作SQL数据库
  • ¥15 MATLAB实现下列
  • ¥30 mininet可视化打不开.mn文件
  • ¥50 C# 全屏打开Edge浏览器
  • ¥80 WEBPACK性能优化
  • ¥30 python拟合回归分析