Validate the language editing form. Reused for custom language addition too.
function language_admin_edit_form_validate($form, &$form_state) {
// Ensure sane field values for langcode and name.
if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state['values']['langcode'])) {
form_set_error('langcode', t('%field may only contain characters a-z, underscores, or hyphens.', array(
'%field' => $form['langcode']['#title'],
)));
}
if ($form_state['values']['name'] != check_plain($form_state['values']['name'])) {
form_set_error('name', t('%field cannot contain any markup.', array(
'%field' => $form['name']['#title'],
)));
}
}