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

conn_id = StringField(
            lazy_gettext("Connection Id"),
            validators=[InputRequired()],
            widget=BS3TextFieldWidget(),
        )
        conn_type = SelectField(
            lazy_gettext("Connection Type"),
            choices=sorted(_iter_connection_types(), key=operator.itemgetter(1)),
            widget=Select2Widget(),
            validators=[InputRequired()],
            description=(
                "Connection Type missing? Make sure you've installed the "
                "corresponding Airflow Provider Package."
            ),
        )
        description = StringField(lazy_gettext("Description"), widget=BS3TextAreaFieldWidget())
        host = StringField(lazy_gettext("Host"), widget=BS3TextFieldWidget())
        schema = StringField(lazy_gettext("Schema"), widget=BS3TextFieldWidget())
        login = StringField(lazy_gettext("Login"), widget=BS3TextFieldWidget())
        password = PasswordField(lazy_gettext("Password"), widget=BS3PasswordFieldWidget())
        port = IntegerField(lazy_gettext("Port"), validators=[Optional()], widget=BS3TextFieldWidget())
        extra = TextAreaField(lazy_gettext("Extra"), widget=BS3TextAreaFieldWidget())
    for key, value in providers_manager.connection_form_widgets.items():
        setattr(ConnectionForm, key, value.field)
    return ConnectionForm