Title: .edu registration only
Last modified: August 22, 2016

---

# .edu registration only

 *  [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/)
 * I would like to only allow registration on my site from .edu email addresses.
   I am getting a lot of spam registrations and I’ve tried a few plugins that can
   block specific domains, but I keep getting new ones. I tried a whitelist plugin,
   but it only allowed for whitelisting full domains (@harvard.edu for example instead
   of *.edu). Any ideas? Thanks!
    Mark
 * [https://wordpress.org/plugins/s2member/](https://wordpress.org/plugins/s2member/)

Viewing 15 replies - 1 through 15 (of 30 total)

1 [2](https://wordpress.org/support/topic/edu-registration-only/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/edu-registration-only/page/2/?output_format=md)

 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286557)
 * I found this code in another forum, but when I tried to add it to functions.php
   file it still allowed registration from .com emails:
 * add_action(‘registration_errors’, ‘validate_email_domain’, 10, 3);
    function 
   validate_email_domain( $errors, $login, $email ) { $expression = “/.*@(.*.edu)/”;
 *  if ( is_email($email) ) {
    if ( !preg_match($expression,$email) ) { $errors-
   >add(’email_domain’, __(‘ERROR: You may only register with a .edu email address.’));}}
   return $errors; }
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286638)
 * Try this:
 *     ```
       add_action('registration_errors', 'validate_email_domain', 10, 3);
       function validate_email_domain( $errors, $login, $email ) {
           if ( is_email($email) and  substr($email, -3) != 'edu' ) {
               $errors->add('email_domain', __('ERROR: You may only register with a .edu email address.'));
           }
           return $errors;
       }
       ```
   
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286651)
 * Thank you!
 * I pasted that code into the bottom of my functions.php page (above the last ?
   >), but when I pressed save it went to a HTTP 500 Internal Server Error page.
   Then the whole site stopped loading until I removed that snippet of code. Any
   ideas?
 *  [KTS915](https://wordpress.org/support/users/kts915/)
 * (@kts915)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286663)
 * Just tried this myself, and I didn’t get an error. Are you sure you didn’t add
   it into another function in that file?
 * In other words, does the last `?>` actually indicate the end of the page, or 
   just the end of the last function? (It isn’t necessary to have a `?>` to end 
   the file. )
 * So maybe try it again, but pasting what krumch has given you _after_ the last`?
   >`?
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286686)
 * I tried adding it after the last ?> and it is now showing at the top of the page:
   [http://www.softwarephd.com/](http://www.softwarephd.com/)
 * Sorry, I’m not very familiar with custom coding. Thanks for your suggestions!
 *  [KTS915](https://wordpress.org/support/users/kts915/)
 * (@kts915)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286719)
 * Then it doesn’t go there!
 * Are you or your host running any caching?
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286730)
 * Not anything I’ve setup that I know of. I use bluehost which is a pretty standard
   hosting service.
 *  [KTS915](https://wordpress.org/support/users/kts915/)
 * (@kts915)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286748)
 * Well, I don’t know what caused the response to krumch’s code.
 * But I realize we should have asked whether you are you using a WordPress registration
   form or an s2Member registration form. Neither code you’ve been given will work
   with s2Member’s registration form.
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286773)
 * Yes, I’m using an s2Member reg form.
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286774)
 * Yes, I’m using an s2Member reg form.
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286782)
 * [@marktvb](https://wordpress.org/support/users/marktvb/): This code should be
   in mu-plugins/s2-hacks.php file. To use it with s2M registration forms, you must
   find a good hook to run the function with. I search in s2M codes – always works
   for me.
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286886)
 * Okay, can you explain that a little more. I’m not sure what exactly to do. What
   do you mean by a hook?
 *  [KTS915](https://wordpress.org/support/users/kts915/)
 * (@kts915)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286898)
 * Perhaps you could try this in `mu-plugins/s2-hacks.php`:
 *     ```
       add_action('ws_plugin__s2member_after_register', 'validate_email_domain', 10, 3);
       function validate_email_domain( $errors, $login, $email ) {
           if ( is_email($email) and  substr($email, -3) != 'edu' ) {
               $errors->add('email_domain', __('ERROR: You may only register with a .edu email address.'));
           }
       return $errors;
       }
       ```
   
 * Let us know if it works!
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286904)
 * Sorry marktvb, somehow I missed your question.
 * Thanks KTS915 for answering 🙂
 *  Thread Starter [marktvb](https://wordpress.org/support/users/marktvb/)
 * (@marktvb)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/edu-registration-only/#post-5286906)
 * I really appreciate your help. When I added that code to the s2-hacks.php file
   the code just showed up at the top of the site. [http://www.softwarephd.com](http://www.softwarephd.com)
 * Did I do something wrong?

Viewing 15 replies - 1 through 15 (of 30 total)

1 [2](https://wordpress.org/support/topic/edu-registration-only/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/edu-registration-only/page/2/?output_format=md)

The topic ‘.edu registration only’ is closed to new replies.

 * ![](https://ps.w.org/s2member/assets/icon-256x256.png?rev=980067)
 * [s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions](https://wordpress.org/plugins/s2member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/s2member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/s2member/)
 * [Active Topics](https://wordpress.org/support/plugin/s2member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/s2member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/s2member/reviews/)

 * 30 replies
 * 4 participants
 * Last reply from: [KTS915](https://wordpress.org/support/users/kts915/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/edu-registration-only/page/2/#post-5286944)
 * Status: not resolved