How to alter a custom form I am using Drupal 7 to create an registration form, there are: username, email dan password fields, but I want to make an username checking while user leave username field (ajax).
I found an module as Username Check

This module is great and working in "myweb/user/register" form, but I need to move this function to my custom form in username field too

The code:

function username_check_menu() {
  $items = array();

  $items['username_check/isunique'] = array(
    'type' =&gt; MENU_CALLBACK,  
    'page callback' =&gt; 'username_check_callback',
    'access arguments' =&gt; array('access content'),
    'file' =&gt; 'username_check.unique.inc',
  );

  $items['admin/config/system/username_check'] = array(
    'title' =&gt; 'Username check',
    'type' =&gt; MENU_NORMAL_ITEM,
    'page callback' =&gt; 'drupal_get_form',
    'page arguments' =&gt; array('username_check_settings'),
    'access arguments' =&gt; array('administer site configuration'),
    'file' =&gt; 'username_check.admin.inc',
  );

  return $items;
}

function username_check_form_user_register_form_alter(&amp;$form) {

  $mode     = variable_get('username_check_mode', 'auto');

  if($mode != 'off') 
  {
    _username_check_load_resources($mode);
    $form['account']['name']['#field_suffix'] = '&lt;span id="username-check-informer"&gt;&amp;nbsp;&lt;/span&gt;';
    $form['account']['name']['#suffix'] = '&lt;div id="username-check-message"&gt;&lt;/div&gt;';
  }

}

/**
 * Load username_check resources.
 */
function _username_check_load_resources($mode) {
  $module_path = drupal_get_path('module', 'username_check');
  drupal_add_css($module_path . '/username_check.css');
  drupal_add_js($module_path . '/username_check.js');

  drupal_add_js(array(
    'usernameCheck' =&gt; array(
      'ajaxUrl' =&gt; url('username_check/isunique', array('absolute' =&gt; TRUE)),
      'delay'   =&gt; variable_get('username_check_delay', 1),
    ),
  ), 'setting');
}


and my form as userregis_form
How to apply this to my custom form?
you need to add a validation to your form via

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


  function yourFunction($form, &amp;$form_state) {
        //to show the form values
        dpm($form_state);
        //do validation
  }