title: How to allow only few special characters in jquery
body: <p>I want to give permission to enter <strong>@</strong> and <strong>&amp;</strong> with normal letters and numbers. But it isn't giving the results I expected.</p>
  
  <p><br/></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>$(document).ready(function() {
    $('#btn').click(function() {
      if(/^[a-zA-Z0-9- ]*$/.test(str) == false) {
      alert('Your search string contains illegal characters.');
  }
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
  &lt;input type="text" name="str" id="str" /&gt;
  &lt;input type="button" name="btn" id="btn" value="btn"/&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Please help me. Thank you.</p>