Validate username field in user registration form, drupal 7 I need to compare the text in the username field with the text in email field of the registration form. If they are not equal i want to stop the registration. I think i should use a hook but i really don't know where to start from.

Any idea?
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.