Question:
How to prevent a specific email address domain from registering in drupal 8 ?
Solution:
The solution is:
- Install Restrict Domain Registration Module .
- visit 'admin/config/system/domain_register'
- Choose if you want to only allow, or disallow the domains from registering
- Enter the domain names you wish to allow/deny (one per line) in the format of 'foo.com'. Wildcards are allowed.
- Enter the error message you wish to show to the end user if the email address doesn't validate
- That's it!
If you want to Restrict Domain Registration just for Anonymous users you can use these patchs. or just override domain_registration.module file like this:
/**
* Implements hook_form_form_id_form_alter().
*/
function domain_registration_form_user_register_form_alter(&$form, &$form_state, $form_id) {
if(\Drupal::currentUser()->isAnonymous()){
$form['#validate'][] = 'domain_registration_user_register_validate';
}
}