Javascript replace function won't remove the string
<p>I have no idea why this doesn't work, but doing some validation functions and trying to output a dynamic message to an alert when they hit submit and forgot to fill out a field. It works only on the second click of the submit button, as far as removing the string, everything else works when it should.</p>

<p><strong>Here's the code:</strong></p>

<pre><code>var fname = $('#fname');
var lname = $('#lname');

function validatefname(){
var a = fname.val().length;

if(a &lt; 2) {
 fname.prev().addClass("error");
 if(msg.search("First Name") == -1) {
   msg+= "-Please enter your First Name\n";
 }
 return false;
} else {
 fname.prev().removeClass("error");
 msg.replace(/Please enter your First Name\n/g, "");
 return true;
}
}

fname.blur(validatefname);
fname.keyup(validatefname);

step4submit.click(function(){
 if(validatefname()) {
  step4form.submit();
  return true
 } else {
  msg+= "\nPlease fill out the fields marked in red";
  alert(msg);
  msg = "";
  return false;
 }
});
</code></pre>
