Conditionally register a user based on fields
Forms have a validate and submit function(s). Submit never runs unless all validation passes.

So all you have to do is add a custom validation

/*
 * Implements hook_form_FORM_ID_alter
 */
function mymodule_form_user_register_form_alter(&amp;$form, FormStateInterface $form_state) {

  $form['#validate'][] = 'mymodule_registration_validate';

}

/*
 * Custom Validation
 */
function mymodule_registration_validate(&amp;$form, FormStateInterface $form_state) {

  $field_name = $form_state-&gt;getValue('field_name'); // Gets the value entered by the user
  // Note: depending on your field type &amp; settings sometimes this value is an
  // array, so you may have to keep drilling down.
  if($field_name != 'Hello World') { // perform check
    $message = t('Only Hello World is allowed'); // message to display
    $form_state-&gt;setErrorByName('field_name', $message); // set error
  }

}


$form_state-&gt;setErrorByName will display an error message and highlight the offending field in red.

If  you want to redirect use $form_state-&gt;setRedirectUrl($url);