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

self.other_field_mock.data = None
        assert self._validate() is None
    def test_both_fields_are_none(self):
        self.form_field_mock.data = None
        self.other_field_mock.data = None
        assert self._validate() is None
    def test_validation_pass(self):
        assert self._validate() is None
    def test_validation_raises(self):
        self.form_field_mock.data = "2017-05-04"
        with pytest.raises(
            validators.ValidationError, match="^Field must be greater than or equal to other field.$"
        ):
            self._validate()
    def test_validation_raises_custom_message(self):
        self.form_field_mock.data = "2017-05-04"
        with pytest.raises(
            validators.ValidationError, match="^This field must be greater than or equal to MyField.$"
        ):
            self._validate(
                message="This field must be greater than or equal to MyField.",
            )
class TestValidJson:
    def setup_method(self):
        self.form_field_mock = mock.MagicMock(data='{"valid":"True"}')
        self.form_field_mock.gettext.side_effect = lambda msg: msg
        self.form_mock = mock.MagicMock(spec_set=dict)
    def _validate(self, message=None):