Validate username field in user registration form, drupal 7
You can do this by using hook_form_FORM_ID_alter() and adding an extra validation function to the user register form:

function MYMODULE_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['#validate'][] = 'MYMODULE_validate_register_form';
}

function MYMODULE_validate_register_form(&amp;$form, &amp;$form_state) {
  if ($form_state['values']['mail'] != $form_state['values']['name']) {
    form_set_error('name', t('Name and email must be the same.'));
  }
}


I'm not 100% positive those $form_state['values'] keys are the right ones so you'll need to inspect the form to make sure; but the logic is the same either way.