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

"""Date time and number of runs and dag runs form for graph and gantt view"""
    execution_date = SelectField("DAG run")
class DagRunEditForm(DynamicForm):
    """Form for editing DAG Run.
    We don't actually want to allow editing, so everything is read-only here.
    """
    dag_id = StringField(lazy_gettext("Dag Id"), widget=BS3TextFieldROWidget())
    start_date = DateTimeWithTimezoneField(lazy_gettext("Start Date"), widget=AirflowDateTimePickerROWidget())
    end_date = DateTimeWithTimezoneField(lazy_gettext("End Date"), widget=AirflowDateTimePickerROWidget())
    run_id = StringField(lazy_gettext("Run Id"), widget=BS3TextFieldROWidget())
    state = StringField(lazy_gettext("State"), widget=BS3TextFieldROWidget())
    execution_date = DateTimeWithTimezoneField(
        lazy_gettext("Logical Date"),
        widget=AirflowDateTimePickerROWidget(),
    )
    conf = TextAreaField(lazy_gettext("Conf"), widget=BS3TextAreaROWidget())
    note = TextAreaField(lazy_gettext("User Note"), widget=BS3TextAreaFieldWidget())
    def populate_obj(self, item):
        """Populates the attributes of the passed obj with data from the form's fields."""
        super().populate_obj(item)
        item.run_type = DagRunType.from_run_id(item.run_id)
        if item.conf:
            item.conf = json.loads(item.conf)
class TaskInstanceEditForm(DynamicForm):