1

Hi I am working on a website for a student organization of my college. In order to prevent spams, I have been looking for ways to limit account applicants only with email addresses from the college but haven't figure out how

4
3

In drupal 6 you can use the built in Access Rules to limit user sign ups to certain domains. It can be found at admin/user/rules/add

This no longer exists in drupal 7 because the functionality was moved into a contrib module called User Restrictions

2
  • how do I block all but one specific domain? – user4109 Nov 21 '11 at 5:02
  • I'm not sure you can, your best bet would be to setup rules that would catch the majority of spammers. Have you looked into modules like Mollom as well? – digital Nov 21 '11 at 10:17
3

You can write a custom module that adds a validation function to the user register form, so the form does not validate if the e-mail address is not correct.

First, tell Drupal about the validation function for the user_register_form form using hook_form_FORM_ID_alter:

function mymodule_form_user_register_form_alter(&$form, &$form_state) {
  $form['#validate'][] = 'mymodule_user_register_validate';
}

Next, we write the validation function. If I'm not mistaken, the email address should be available as $form_state['values']['mail'] here.

function mymodule_user_register_validate($form, &$form_state) {
  $valid_email = false;

  // Write your own code here to check if the email address is valid.
  // If so, set $valid_email to true.

  // If the email address is not valid, tell Drupal that validation failed.
  if (!$valid_email) {
    form_set_error('mail', t('The e-mail address %email is not valid for this site.', array('%email' => $form_state['values']['mail'])));
  }
}

Please note that the code above is written with best intentions, but untested.

1

To build on digital's answer, I had the same issue, with the same Drupal version. I looked into the built-in Access Rules and created two rules: one that denies all email addresses fitting the mask "%" (i.e. all email addresses) and one that allows only email addresses fitting the mask "%@%.edu". Even if the rules conflict on the ".edu" addresses, it works and results in only allowing the registrations of ".edu" email addresses.

Thanks user4109 for asking that question, and thanks digital for pointing in the right and easy solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.