I have a javascript code I got off of this forum that takes an inputted ten digit number and adds formatting (ie 1234567891 gets changed to (123) 456-7891).
I have a field that will always be ######-###### and I'd like to modify the code to add the dash in the middle. What I'm trying to avoid is having someone needing to click on multiple boxes to fill out the entire field.
I'm not great with javascript, so I was hoping someone on here would be able to help me with that.
Here is the code:
<SCRIPT LANGUAGE="JavaScript">
function f_a(v_id)
{
return document.getElementById(v_id);
}
f_a('InsertRecordPhone').maxLength = 14;
f_a('InsertRecordPhone').onkeyup = function(v_e)
{
v_e = v_e || window.event;
if (v_e.keyCode >= 65 && v_e.keyCode <= 90){
this.value = this.value.substr(0, this.value.length - 1);
return false;
}else if (v_e.keyCode >= 37 && v_e.keyCode <= 40){
return true;
}
var v_value =(this.value.replace(/[^\d]/g, ''));
if (v_value.length==7) {
this.value = (v_value.substring(0,3) + "-" + v_value.substring(3,7));}
else if(v_value.length==10){
this.value = ("(" + v_value.substring(0,3) + ") " + v_value.substring(3,6) + "-" + v_value.substring(6,10));
};
}
</SCRIPT>