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

#
#
#
from __future__ import annotations
import json
from typing import Any
from unittest import mock
from unittest.mock import PropertyMock
import pytest
from pytest import param
from airflow.models import Connection
from airflow.utils.session import create_session
from airflow.www.views import ConnectionFormWidget, ConnectionModelView
from tests.test_utils.www import _check_last_log, _check_last_log_masked_connection, check_content_in_response
CONNECTION: dict[str, Any] = {
    "conn_id": "test_conn",
    "conn_type": "http",
    "description": "description",
    "host": "localhost",
    "port": 8080,
    "username": "root",
    "password": "admin",
}
def conn_with_extra() -> dict[str, Any]:
    return {**CONNECTION, "extra": '{"x_secret": "testsecret","y_secret": "test"}'}
@pytest.fixture(autouse=True)
def clear_connections():