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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵