Issue with spaces in JavaScript function
<p>I have created JavaScript code for validation of a simple text field. The issue is when I want to skip spaces in field,</p>

<pre><code>var strFilter = /^[A-Za-z]*$/;

var chkVal2 = document.getElementById("fname").value.replace(/^\s+|\s+$/g, "");
if ((!strFilter.test(chkVal2)) || (chkVal2 == "")) {
    alert("Please enter a valid first name\r\n (only characters)");
    document.getElementById("fname").style.background = "#DFE32D";
    document.getElementById("fname").focus();
    document.getElementById("fname").value = null;
    return false;
}
</code></pre>

<p>Here I want, when the value is checked, it removes all spaces in ID. The script is going well, but it's not removing spaces.</p>
