### 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)

with create_session() as session:
        session.query(Connection).delete()
def test_create_connection(admin_client, session):
    resp = admin_client.post("/connection/add", data=CONNECTION, follow_redirects=True)
    check_content_in_response("Added Row", resp)
    _check_last_log(session, dag_id=None, event="connection.create", execution_date=None)
def test_action_logging_connection_masked_secrets(session, admin_client):
    admin_client.post("/connection/add", data=conn_with_extra(), follow_redirects=True)
    _check_last_log_masked_connection(session, dag_id=None, event="connection.create", execution_date=None)
def test_prefill_form_null_extra():
    mock_form = mock.Mock()
    mock_form.data = {"conn_id": "test", "extra": None, "conn_type": "test"}
    cmv = ConnectionModelView()
    cmv._iter_extra_field_names = mock.Mock(return_value=())
    cmv.prefill_form(form=mock_form, pk=1)
@pytest.mark.parametrize(
    "extras, expected",
    [
        param({"extra__test__my_param": "this_val"}, "this_val", id="conn_not_upgraded"),
        param({"my_param": "my_val"}, "my_val", id="conn_upgraded"),
        param(
            {"extra__test__my_param": "this_val", "my_param": "my_val"},
            "my_val",
            id="conn_upgraded_old_val_present",
        ),
    ],
)
def test_prefill_form_backcompat(extras, expected):