title: Forbidden characters in input form?
body: <p>This is my current code it removes all non-numeric characters except $, commas and dots from an input when as user types:</p>
  
  <pre><code>&lt;input type="text" id="price" name="price" onkeyup="updatePrice(this.value)"&gt;
  
  function updatePrice(p) {
      document.getElementById("price").value = p.replace(/[^0-9$.,]/g, '');
      }
  </code></pre>
  
  <p>The problem is that it removes characters after typing them so if you type A you see it for a fraction of a second before it disappears. Keydown is no good since it runs the script before the input actually changes.</p>
  
  <p>How can I completely prevent these forbidden characters from appearing on the input?</p>