var zChar = new Array(' ', '(', ')', '-', '.'); var maxphonelength = 14; var phonevalue1; var phonevalue2; var cursorposition; function ParseForNumber1(object){ phonevalue1 = ParseChar(object.value, zChar); } function ParseForNumber2(object){ phonevalue2 = ParseChar(object.value, zChar); } function backspacerUP(object,e) { if(e){ e = e } else { e = window.event } if(e.which){ var keycode = e.which } else { var keycode = e.keyCode } ParseForNumber1(object) if(keycode >= 48){ ValidatePhone(object) } } function backspacerDOWN(object,e) { if(e){ e = e } else { e = window.event } if(e.which){ var keycode = e.which } else { var keycode = e.keyCode } ParseForNumber2(object) } function GetCursorPosition(){ var t1 = phonevalue1; var t2 = phonevalue2; var bool = false for (i=0; i3 && p.length < 7){ p ="(" + p; l30=p.length; p30=p.substring(0,4); p30=p30+") "; p31=p.substring(4,l30); pp=p30+p31; object.value = pp; } else if(p.length >= 7){ p ="(" + p; l30=p.length; p30=p.substring(0,4); p30=p30+") "; p31=p.substring(4,l30); pp=p30+p31; l40 = pp.length; p40 = pp.substring(0,9); p40 = p40 + "-"; p41 = pp.substring(9,l40); ppp = p40 + p41; object.value = ppp.substring(0, maxphonelength); } GetCursorPosition(); if(cursorposition >= 0){ if (cursorposition == 0) { cursorposition = 2 } else if (cursorposition <= 2) { cursorposition = cursorposition + 1 } else if (cursorposition <= 4) { cursorposition = cursorposition + 3 } else if (cursorposition == 5) { cursorposition = cursorposition + 3 } else if (cursorposition == 6) { cursorposition = cursorposition + 3 } else if (cursorposition == 7) { cursorposition = cursorposition + 4 } else if (cursorposition == 8) { cursorposition = cursorposition + 4 e1=object.value.indexOf(')') e2=object.value.indexOf('-') if (e1>-1 && e2>-1){ if (e2-e1 == 4) { cursorposition = cursorposition - 1 } } } else if (cursorposition == 9) { cursorposition = cursorposition + 4 } else if (cursorposition < 11) { cursorposition = cursorposition + 3 } else if (cursorposition == 11) { cursorposition = cursorposition + 1 } else if (cursorposition == 12) { cursorposition = cursorposition + 1 } else if (cursorposition >= 13) { cursorposition = cursorposition } var txtRange = object.createTextRange(); txtRange.moveStart( "character", cursorposition); txtRange.moveEnd( "character", cursorposition - object.value.length); txtRange.select(); } } function ParseChar(sStr, sChar) { if (sChar.length == null) { zChar = new Array(sChar); } else zChar = sChar; for (i=0; i 0) { if(p.length==14){ p0 = p.substr(0,1); p1 = p.substr(1,1); p2 = p.substr(2,1); p3 = p.substr(3,1); p4 = p.substr(4,1); p5 = p.substr(5,1); p6 = p.substr(6,1); p7 = p.substr(7,1); p8 = p.substr(8,1); p9 = p.substr(9,1); p10 = p.substr(10,1); p11 = p.substr(11,1); p12 = p.substr(12,1); p13 = p.substr(13,1); if ( (p0 == '(') && (isNumb(p1)) && (isNumb(p2)) && (isNumb(p3)) && (p4 == ')') && (p5 == ' ') && (isNumb(p6)) && (isNumb(p7)) && (isNumb(p8)) && (p9 == '-') && (isNumb(p10)) && (isNumb(p11)) && (isNumb(p12)) && (isNumb(p13)) ) { return true; } else { alert("The phone number entered is not valid. Please only enter numerics. '(', ') ' and '-' will be filled in automatically."); tov = setTimeout("setFocus('" + m.id + "');", 1); return false; } } else { alert("The phone number entered must be like (800) 123-4567. Please re-enter with only numerics. '(', ') ' and '-' will be filled in automatically."); tov = setTimeout("setFocus('" + m.id + "');", 1); return false; } } return true; } //set focus work around for FF and cursor at end of textbox for IE function setFocus(id) { var control = document.getElementById(id); pp = control.value; setCaretPosition(id, pp.length); } //onfocus function getIt(m){ var n=m.name; var fieldname=m.name; var formname = m.form.name; //'document.forms[0]'; //td 8/7/09 problem when using same js in many forms in 1 page var fdis = formname + '.' + fieldname + '.disabled == true'; //alert(eval(fdis)); if (eval(fdis)) // if the field is disabled, don't do anything it return; //New: if existing phone # is of 13 chars format, chg to new format w/ a space after ) var p=m.value; if(p.length == 13) { //alert("old format " + p); var d5=p.indexOf(') '); if(d5 == -1){ var pp = p.replace(")", ") "); //alert("new format " + pp); m.value = pp; setCaretPosition(m.id, 14); } } } // IE cursor jumps to begin of text so must use this fct. function setCaretPosition(elemId, caretPos) { var elem = document.getElementById(elemId); if(elem != null) { if(elem.createTextRange) { var range = elem.createTextRange(); range.move('character', caretPos); range.select(); } else { if(elem.selectionStart) { elem.focus(); elem.setSelectionRange(caretPos, caretPos); } else elem.focus(); } } }