【问题标题】:How to understand if an e-mail address is an education e-mail address or not?如何判断一个邮箱地址是不是教育邮箱?
【发布时间】:2012-11-22 23:53:00
【问题描述】:

我希望只有大学生能够注册我的网站,但我不知道如何控制它。我还希望 .edu.fr、edu.tr 或其他 .edu 扩展名能够加入我的网站,而不仅仅是 .edu 的。我正在考虑使用一些 reg-ex,但我找不到任何解决方案。如果有人可以帮助我,我会很高兴?

应该没那么重要,但我使用的是带有 laravel 框架的 PHP。

【问题讨论】:

标签: php email web laravel


【解决方案1】:

大多数教育机构的域名都遵循以下模式:

uni.edu
uni.edu.fr
uni.ac.uk

以下正则表达式涵盖了所有此类情况:

/(\.edu(\.[a-z]+)?|\.ac\.[a-z]+)$/

您可以根据需要向正则表达式添加案例。通过发送带有确认链接的自动电子邮件来检查电子邮件是否真实。

对应的PHP:

if (preg_match('/(\.edu(\.[a-zA-Z]+)?|\.ac\.[a-zA-Z]+)$/i', $domain)) {
    // allow
}

【讨论】:

    【解决方案2】:

    没有很好的方法,但一种可能的方法是使用@符号来分解地址:

    // Split the email address into 2 values of an array using the @ symbol as delimiter.
    $emailParts = explode('@', $theEmailAddress);
    // If the second part (domain part) contains .edu, period, country code or just .edu, then allow signup.
    if (preg_match('/\.edu\.[^.]+$/i', trim($emailParts[1])) || preg_match('/\.edu$/i', trim($emailParts[1]))) {
        // Use the above if you are assuming that the country codes can be any number of characters. If you know for sure country codes are 2 chars, use this condition:
        // (preg_match('/\.edu\.[^.]{2}$/i', trim($emailParts[1])) || preg_match('/\.edu$/i', trim($emailParts[1])))
        // Allow signup
    }
    

    当然,这并不能保证域或电子邮件地址是现有的!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 2012-09-17
      • 1970-01-01
      • 2013-11-07
      相关资源
      最近更新 更多