How do I know if an email address is an educational email address or not?

I want only college students to register on my site, but I could not figure out how to control this. I also want .edu.fr, edu.tr or other .edu extensions to be able to join my site not only .edu. I was thinking about using some kind of reg-ex, but I could not find a solution. I would be glad if anyone can help me?

It shouldn't be that important, but I'm using PHP with the laravel framework.

+4
source share
2 answers

Most schools have domain names that follow this pattern:

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

The following regular expression covers all such cases:

 /(\.edu(\.[az]+)?|\.ac\.[az]+)$/ 

If necessary, you can add cases to the regular expression. Make sure that the letter is valid by sending an automatic letter with a confirmation link.

Relevant php:

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

There is no great way to do this, but one possible way would be to explode the address using the @ symbol:

 // 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 } 

Of course, this does NOT guarantee that the domain or email address is already existing!

+1
source

All Articles