Was trying to achieve, an auto dash for this format XXX-XXX-XXXX
Here's what I have so far:
$('.telnumber').keyup(function() {
var foo = $(this).val().split("-").join(""); // remove hyphens
foo = foo.match(new RegExp('.{1,3}', 'g')).join("-");
$(this).val(foo);
});
First 2 blocks are fine, but How can I restrict the last block to accept 4 digits?
It's still auto dashing if there are 3 digits so far.
I'm not good at REGEX so any ideas will be appreciated.