How do I trim space in an input field? : <p>I am using an input field and when someone types in it they can add spaces as general behavior. I do not want anyone to add spaces into the field and even if someone adds one it should trim there and then.</p>

<p>Can someone please help on how to achieve this?</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text"&gt;</code></pre>
</div>
</div>
</p>
