The logic you’re checking here wouldn’t really work for what you’re trying to do.
You would first want to start with allowing all the standard validation in the plugin to do its checks prior to running anything custom, then flagging the submission as invalid until your custom check passes.
You’d then want to loop through each allowed domain you’ve declared and then change the validation result back to true if you find a partial match in an email field value.
Something like the following would roughly do the above. Remember that this and your original snippet would only run for form #4 as defined in the filter name on the first line.
add_filter( 'gform_field_validation_4','validate_email', 10, 4);
function validate_email ( $result, $value, $form, $field ) {
$whitelisted_domain = array(
'domain1.com',
'domain2.com'
);
if ( $field->get_input_type() === 'email' && $result['is_valid'] ) {
$result['is_valid'] = false;
$result['message'] = 'E-Mailadresse not approved.';
foreach ( $whitelisted_domain as $term ) {
if ( strpos( $value, $term ) ) {
$result['is_valid'] = true;
break;
}
}
}
return $result;
}