Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand if an e-mail address is an education e-mail address or not?

I want only college students to be able to sign up my website, but I couldn't figure out how to control that. I also want .edu.fr, edu.tr or other .edu extensions to be able to join my website not just .edu's. I was thinking about using some reg-ex but I couldn't find any solution. I would be glad if someone can help me?

Shouldn't be that important but I am using PHP with laravel framework.

like image 669
bamya Avatar asked Oct 05 '22 18:10

bamya


1 Answers

Most educational institutions have domain names that follow these pattern:

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

The following regular expression covers all such cases:

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

You can add cases to the regex as needed. Check that the email is real by sending an automated email with a confirmation link.

Corresponding PHP:

if (preg_match('/(\.edu(\.[a-zA-Z]+)?|\.ac\.[a-zA-Z]+)$/i', $domain)) {
    // allow
}
like image 141
Kevin A. Naudé Avatar answered Oct 09 '22 15:10

Kevin A. Naudé