Could someone help with a regular expression. I'm trying to format a phone number and handle an range of extension digits. I tried using a range [1-5], but that doesn't seem to work.
$(".phone").text(function(i, text) {
if(text.length == 10) { //this portion works fine
text = text.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
return text;
}else if (text.length > 10) { //this is where I need help
text = text.replace(/(\d{3})(\d{3})(\d{4})(\d{[1-5]})/, "($1) $2-$3 x$4");
return text;
}
});
Is there a regular expression to handle a range of numbers here?