title: JQuery - remove the chars not matching regEx
body: <p>I am trying to use jquery for validating forms.</p>
  
  <p>This is the pattern that is allowed in a text box for a user.</p>
  
  <pre><code>var pattern = /^[a-zA-Z0-9!#$&amp;%*+,-./: ;=?@_]/g;
  </code></pre>
  
  <p>If the user types anything else other than this then that has to be replaced with a "".</p>
  
  <pre><code>$(document).ready(function() {
    $('#iBox').blur(function() {
       var jVal = $('#iBox').val();
    if(jVal.match(pattern)) {
     alert("Valid");
    } else {
     alert("New "+jVal.replace(!(pattern),""));
                  }
      });
    });
  });
  </code></pre>
  
  <p>But the replace function does not work this way.</p>