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

"""
    When populating custom fields in the connection form we should first check for the non-prefixed
    value (since prefixes in extra are deprecated) and then fallback to the prefixed value.
    Either way, the field is known internally to the model view as the prefixed value.
    """
    mock_form = mock.Mock()
    mock_form.data = {"conn_id": "test", "extra": json.dumps(extras), "conn_type": "test"}
    cmv = ConnectionModelView()
    cmv._iter_extra_field_names = mock.Mock(return_value=[("extra__test__my_param", "my_param")])
    cmv.prefill_form(form=mock_form, pk=1)
    assert mock_form.extra__test__my_param.data == expected
@pytest.mark.parametrize("field_name", ["extra__test__custom_field", "custom_field"])
@mock.patch("airflow.utils.module_loading.import_string")
@mock.patch("airflow.providers_manager.ProvidersManager.hooks", new_callable=PropertyMock)
def test_process_form_extras_both(mock_pm_hooks, mock_import_str, field_name):