vasudeesha
vasudeesha

Reputation: 1

Drupal webform email field restrict free email

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 How to write regular expression to match free email accounts? in stackoverflow but dont know how to implement in webform email field.

Upvotes: 0

Views: 655

Answers (1)

Jeremy French
Jeremy French

Reputation: 12177

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.'));
   }
}

Upvotes: 0

Related Questions