Optgroup in drupal 7 list field Now I'm having like

1|City name
2|Another city name
3|Little town name

in values field when creating content type field

How can I wrap some of them in a group that will appear as “optgroup” in html generated?
you can use a hook_FORM_ID_alter and then add code like this:

$form['FIELDNAME']['#options'] = array (

   'parent1' =&gt; array(
      3 =&gt; 'child1',
      4 =&gt; 'child2',
      5 =&gt; 'child3',
    ),
    'parent2' =&gt; array(
      8 =&gt; 'child1',
      9 =&gt; 'child2',
    ),
);