title: Replace multiple characters in string on keyup
body: <p>I want to help my users to add a correct string do be used as a meta_key in the database by not allowing illegal characters and replacing bad characters with good ones. I have this and its working great. </p>
  
  <pre><code>$('.custom_field_name').keyup(function () { 
      var v = this.value.replace(/\W/,'');
      if (v!=this.value) this.value = v;
  });
  </code></pre>
  
  <p>But i also want to replace space '   ' with a underline '_', and I have been trying codes like this, not getting anywhere.</p>
  
  <pre><code>$('.custom_field_name').keyup(function () { 
      var v = this.value.replace(/\W/,'') &amp;&amp; (' ','_');
      if (v!=this.value) this.value = v;
  });
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$('.custom_field_name').keyup(function () { 
      var v = this.value.replace(/\W/,'');
      var v = this.value.replace(' ','_');
      if (v!=this.value) this.value = v;
  });
  </code></pre>