PHP Check domain of email being registered is a 'school.edu' address

Viewed 31227

I need to write a function for a project i'm working on for fun, where we're making a site only accessible to students, staff, and alumni at an institution.

Let's say the schools website is: school.edu.

I'm having trouble writing a php filter that checks that the submitted email address has the domain of "school.edu"

I'll use an example. Dude #1 has an email of user@mail.com and Dude #2 has an email at user@school.edu. I want to make sure that Dude 1 gets an error message, and Dude #2 has a successful registration.

That's the gist of what I'm trying to do. In the near future the site will allow registration by another two locale schools: school2.edu and school3.edu. I will then need the checker to check the email against a small list (maybe an array?) of domains to verify that the email is of a domain name on the list.

7 Answers

If you are using Laravel:

Str::endsWith($email, '@foo.bar.edu'); // bool
Related