How to delete extra spaces in an input type="text"? : <p>I got this input type="text" and this button which shows the users input, but if the input have extra spaces, them will be showed too.How to remove these extra spaces form the input value?</p>

<p></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-js lang-js prettyprint-override"><code>var nameInput = $('#name');

function showName() {
    if (nameInput.val() === "") {
      alert('You must provide a Name');
    }
    else {
      alert('¡Hello' + ' ' + nameInput.val() + '!')
    }
};</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;input type="text" id="name" /&gt;
&lt;button type="button" onclick="showName()"&gt; Show Name &lt;/button&gt;</code></pre>
</div>
</div>
</p>
