views:

22

answers:

1

Hi

I am using webform in drupal to capture users email address, but I want to restrict the user to enter free emails like gmail, yahoo, rediffmail etc. only corporate email should accepted. Can anybody please let me know how to do that? I got this http://stackoverflow.com/questions/2318214/regular-expression-to-match-free-email-accounts in stackoverflow but dont know how to implement in webform email field.

A: 

use hook_form_alter(). Well actually hook_form_FORM_ID_alter to set the 'element_validate' property.

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

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