as @Geat said:
Your form should be like below.
$form['usershare'] = array(
'#title' => t('Share Collection with:'),
'#type' => 'textfield',
'#autocomplete_path' => 'user/autocomplete',
'#multiple' => TRUE,
);
// Implemenbts hook_menu() for user/autocomplete path.
function module_name_menu() {
$items['user/autocomplete'] = array(
'page callback' => '_user_autocomplete',
'access arguments' => array('access user autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
// Implements callback function to get users in autocomplete with comma seperated
function _user_autocomplete($string) {
if ($string) {
$items = array_map('trim', explode(',', $string));
$last_item = array_pop($items);
$prefix = implode(', ', $items);
$result = db_select('users')->fields('users', array('name'))->condition('name', '%' . db_like($last_item) . '%', 'LIKE')->range(0, 10)->execute();
foreach ($result as $user) {
$value = !empty($prefix) ? $prefix . ', ' . $user->name : $user->name;
$matches[$value] = check_plain($value);
}
}
// return output in JSON format.
drupal_json_output($matches);
}