title: put dash after every n character during input from keyboard
body: <pre><code>$('.creditCardText').keyup(function() {
    var foo = $(this).val().split("-").join(""); // remove hyphens
    if (foo.length &gt; 0) {
      foo = foo.match(new RegExp('.{1,4}', 'g')).join("-");
    }
    $(this).val(foo);
  });
  </code></pre>
  
  <p>I found this tutorial on putting dash after every 4 character from <a href="https://stackoverflow.com/questions/11632525/insert-dash-after-every-4th-character-in-input">here</a> my question is what if the character interval is not constant like in this example it is only after every 4 what if the interval is <code>3 characters "-" 2 characters "-" 4 characters "-" 3 characters "-"</code> so it would appear like this <code>123-12-1234-123-123</code>. </p>