title: Javascript Regular Expression to add dash after every 3rd and 4th characters
body: <p>The following regex:</p>
  
  <pre><code>x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, "-"); 
  </code></pre>
  
  <p>adds dash after each <strong>3rd</strong> character so entered <code>123456789</code> turns into <code>123-456-789</code>.
  Im trying to use this regex to format phone number. The problem arises on the 10th character. So entered <code>1234567890</code> turns into <code>1-234-567-890</code>.</p>
  
  <p>How would I modify the above regex to turn strings that have 10 digits into <code>123-456-7890</code>. I use this regex because this happens as user is typing in uses <strong>keyup</strong> event.</p>
  
  <p>If you know easier or better way of doing this please help me out, dashes has to be added while user is typing in. No other characters allowed. </p>
  
  <p><strong>Notes:</strong></p>
  
  <ol>
  <li>Cant use Jquery Masked input plugin (because if editing the middle character it's focus gets messed up)</li>
  </ol>