Using hook_form_alter() to prevent free email addresses from registering on a Drupal 6 site I have been tasked with blocking specific email address domians from registering at our Drupal 6 site (gmail.com, aol.com &amp; yahoo.com). I implemented some JQuery code to do this but the problem was that spammers with javascript disabled in their browser readily bypassed this prevention. 

I also cannot use Drupal 6's Access Rules as we already have registered users on the site with those domains so this method blocks them from logging in so it's more of a going forward prevention that we would like to implement. 

I found this code on Stack Overflow but the code was somewhat incomplete:

function example_data_form_user_register_alter(&amp;$form,&amp;$form_state) {
  $form['mail']['#element_validate'] = 'example_mail_validate';
}

function example_mail_validate($element, &amp;$form_state) {
   if ( -- Whatever condition you like -- ) {
     form_error($element, t('Free email is not allowed.'));
   }
}


I thought it would be better to open a new question on this forum since it's Drupal specific. 

I think what I need help with is filling in the gap where in the code it says: -- Whatever condition you like --

I am not a PHP guru so any help would be appreciated. I assume this is the spot where I would have some code that disallows the domains that I want to block.
A very simple example would be:

function example_mail_form_user_register_alter(&amp;$form,&amp;$form_state) {
  $form['mail']['#element_validate'] = array('example_mail_validate');
}

function example_mail_validate($element, &amp;$form_state) {
   //block gmail addresses
   if (stripos($form_state['values']['mail'], 'gmail.com') &gt; 0) {
     form_set_error('mail', t('Free email is not allowed.'));
   }
}


However you should lookout for more advanced solutions:


Simple email verification: email verify
http:BL 


  http:BL can prevent email address harvesters and comment spammers from
  visiting your site by using a centralized DNS blacklist.
  Mollom which also prevent spam on all your content/comments forms.