Just copy the above code and paste it into your theme’s functions.php file.
Here I am going to show you the code which will reject registration from all others domain’s email addresses and Only allowing @uniname.ac.uk email addresses to create an account. See the code below
function is_valid_email_domain($login, $email, $errors ){
$valid_email_domain = array("uniname.ac.uk");
$valid = false;
foreach( $valid_email_domain as $d ){
$d_length = strlen( $d );
$current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
if( $current_email_domain == strtolower($d) ){
$valid = true;
break;
}
}
if( $valid === false ){
$errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using @uniname.ac.uk emails' ));
}
}
add_action('register_post', 'is_valid_email_domain',10,3 );