best practice for email validation in form alter drupal 7 What is the best recommended drupal way to validate an email is input on a new field I added in drupal settings page? Here is the code I have now:

function MYMODULE_form_uc_order_settings_form_alter(&amp;$form, &amp;$form_state, $form_id) {   $form['MYMODULE_uc_order_template_email'] = array(
'#title' =&gt; t('Template Email'),
'#default_value' =&gt; variable_get('MYMODULE_uc_order_template_email', 'test@example.com'),
'#description' =&gt; t("Template Email"),
'#type' =&gt; 'textfield',
 );


}
The function valid_email_address($mail) in D7 validates any email passed into it. If you need to validate a new email field from a form altered form, you can add a validation handler to your newly add email field to ensure that it is valid. Just append to the $form['#validate'] array the function you want called for validation.

function MYMODULE_form_uc_order_settings_form_alter(&amp;$form, &amp;$form_state, $form_id)
  //@TODO: Other form modifications
  $form['#validate'][] = 'MYMODULE_form_uc_order_settings_form_validate';
}


Then in your form validation function, check the value of the submitted field with valid_email_address($mail).

function MYMODULE_form_uc_order_settings_form_validate($form, &amp;$form_state) {
  if (!valid_email_address($form_state['values']['MYMODULE_uc_order_template_email'])) {
    form_set_error('MYMODULE_uc_order_template_email', 'Not a valid email address');
  }
}