I am trying to write a regex for US phone numbers where user can enter the number and dash comes automatically. But here the drawback is if user enters "123" and then "-" the regex breaks and instead of 123-456-7890 it becomes 123-4567890 Here is the regex code:
$('#AccountFrm_telephone').attr('maxlength', '12');
$('#AccountFrm_telephone').keyup(function(){
$(this).val($(this).val().replace(/^(\d{3})(\d{3})(\d)+$/, "$1-$2-$3"));
});
Maybe There is something that we add in regex so that user can not type dash?