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

"""Create a form class for editing and adding Connection.
    This class is created dynamically because it relies heavily on run-time
    provider discovery, which slows down webserver startup a lot.
    By creating the class at runtime, we can delay loading the providers until
    when the connection form is first used, which may as well be never for a
    short-lived server.
    """
    providers_manager = ProvidersManager()
    def _iter_connection_types() -> Iterator[tuple[str, str]]:
        """List available connection types."""
        yield ("email", "Email")
        yield ("fs", "File (path)")
        yield ("generic", "Generic")
        yield ("mesos_framework-id", "Mesos Framework ID")
        for connection_type, provider_info in providers_manager.hooks.items():
            if provider_info:
                yield (connection_type, provider_info.hook_name)
    class ConnectionForm(DynamicForm):