title: Javascript string replacement not taking effect until length fulfilled instead of instantanoeus
body: <p>I have an <code>html element</code> that inputs a phone number. It has both an <code>onkeyup</code> and <code>onkeydown</code> events that do this:</p>
  
  <pre><code>document.getElementById("phone").value = document.getElementById("phone").value.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
  </code></pre>
  
  <p>Now, when I use this it works fine however it only makes the changes once the user has typed 10 numbers. <strong>What I'm looking for is instantaneous updates that show the formatting while the user is typing</strong>. </p>
  
  <p>I don't know how to modify the code to make it work as so.</p>