you are correct.
Not only I forgot to do that but also a general replace of white spaces
for example
123 456 7890
123. 456. 7890
It's my personal belief that all of them should pass the test and be considered as valid phone number.
As usual I got caught in the formatting for tek-tips and the name of the index "i". please replace the previous code I posted with this new one.
again thos bolded alerts are for debugging only.
<script type="text/javascript">
function formatphone(digits,format){
var txtphone;
var txtfirst=digits.substr(0,3);
var txtmiddle=digits.substr(3,3);
var txtlast=digits.substr(6,4);
switch (format){
case 0:
//have a format here
break;
case 1:
//have another format here
break;
case 2:
txtphone="("+txtfirst+"

"+txtmiddle+"-"+txtlast;
break;
}//endswitch
return txtphone;
}
function checkphone(elem){
var phoneFormats=new Array();
phoneFormats[0]=/^\d{10}$/; //1234567890
phoneFormats[1]=/^\(\d{3}\)\d{3}\-\d{4}$/; //(123)456-7890
phoneFormats[2]=/^\d{3}\-\d{3}\-\d{4}$/; //123-456-7890
phoneFormats[3]=/^\d{3}\.\d{3}\.\d{4}$/; //123.456.7890
// you can add as many different formats and combinations as you want by adding elements to the array.
var boophone=false;
var txtphone=elem.value.replace(/\s/g,'');
alert('phone: |'+txtphone+'|');
for(var index=0;index<phoneFormats.length;index++){
alert(elem.value+' : '+phoneFormats[index].test(txtphone)+':'+ phoneFormats[index])
if(phoneFormats[index].test(txtphone)){
boophone=true;
}//endif
}//endfor
if(!boophone){
alert('The phone number is incorrect');
elem.select();
elem.focus();
}else{
//do any kind of formatting here. even call a function that does the formatting for you.
elem.value=formatphone(elem.value.replace(/[^\d]/g,''),2);//pass only the digits and from there let the function format the phone based in an index of your preference
}
}//endfunc
</script>
grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein