title: Auto Format Phone Number in Jquery
body: <p>I have one textbox for phone number. My phone number should be XXX-XXX-XXX like this format.</p>
  
  <p>I got the solution for XXX-XXX-XXX format, but i don't know how to modify that code.</p>
  
  <pre><code>$('#ssn').keyup(function() {
      var val = this.value.replace(/\D/g, '');
      var newVal = '';
      while (val.length &gt; 3) {
        newVal += val.substr(0, 3) + '-';
        val = val.substr(3);
      }
      newVal += val;
      this.value = newVal;
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/ssthil/nY2QT/" rel="noreferrer">http://jsfiddle.net/ssthil/nY2QT/</a></p>