我希望只有大学生才能注册我的网站,但我不知道如何控制。我还希望.edu.fr、edu.tr或其他.edu扩展能够加入我的网站,而不仅仅是.edu的。我正在考虑使用一些reg-ex,但我找不到任何解决方案。如果有人能帮我,我会很高兴的。
这不是很重要,但我使用的是带有laravel框架的PHP。
发布于 2012-12-05 15:52:38
大多数教育机构的域名都遵循以下模式:
uni.edu
uni.edu.fr
uni.ac.uk下面的正则表达式涵盖了所有这些情况:
/(\.edu(\.[a-z]+)?|\.ac\.[a-z]+)$/您可以根据需要将案例添加到regex中。通过发送带有确认链接的自动电子邮件来检查电子邮件是否真实。
对应的PHP:
if (preg_match('/(\.edu(\.[a-zA-Z]+)?|\.ac\.[a-zA-Z]+)$/i', $domain)) {
// allow
}发布于 2012-12-05 15:45:51
没有一个很好的方法可以做到这一点,但一种可能的方法是使用@符号分解地址:
// 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
}当然,这并不能保证域名或电子邮件地址是现有的!
https://stackoverflow.com/questions/13718426
复制相似问题