Stop multiple spaces in text

I’m not sure if this is a Yii question, or a more general PHP, javascript/jQuery one, but I’ve encountered an issue in which a user inadvertently added multiple space in text (so instead of single spaces between words, they accidentally had inserted 2-3 in a row) which later caused problems. So, I’m wondering what I can do to stop this.

Is this something I should be sanitizing at the controller level, model (beforeSave), in the form using javascript/jQuery.

Any advice is welcome.

Thank you

I would add a filter with regex to prevent it. So in terms of Yii it would be for example filter validation rule.