### Description

I bumped into a bug where a connection id was suffixed with a whitespace e.g. "myconn ". When referencing the connection id "myconn" (without whitespace), you get a connection not found error.

To avoid such human errors, I suggest restricting the characters allowed for connection ids.

Some suggestions:
- There's an `airflow.utils.helpers.validate_key` function for validating the DAG id. Probably a good idea to reuse this.
- I believe variable ids are also not validated, would be good to check those too.

### Use case/motivation

_No response_

### Related issues

_No response_

### Are you willing to submit a PR?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

"""
    Test the handling of connection parameters set with the classic `Extra` field as well as custom fields.
    The key used in the field definition returned by `get_connection_form_widgets` is stored in
    attr `extra_field_name_mapping`.  Whatever is defined there is what should end up in `extra` when
    the form is processed.
    """
    mock_pm_hooks.get.return_value = True  
    
    mock_form = mock.Mock()
    mock_form.data = {
        "conn_type": "test",
        "conn_id": "extras_test",
        "extra": '{"param1": "param1_val"}',
        "extra__test__custom_field": "custom_field_val",
        "extra__other_conn_type__custom_field": "another_field_val",
    }
    cmv = ConnectionModelView()
    cmv._iter_extra_field_names = mock.Mock(return_value=[("extra__test__custom_field", field_name)])
    cmv.process_form(form=mock_form, is_created=True)
    assert json.loads(mock_form.extra.data) == {
        field_name: "custom_field_val",
        "param1": "param1_val",
    }
@mock.patch("airflow.utils.module_loading.import_string")
@mock.patch("airflow.providers_manager.ProvidersManager.hooks", new_callable=PropertyMock)
def test_process_form_extras_extra_only(mock_pm_hooks, mock_import_str):