Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/03/2010, 17:28
webrek
 
Fecha de Ingreso: abril-2005
Ubicación: Ciudad de México
Mensajes: 50
Antigüedad: 19 años
Puntos: 2
Formato de números telefonicos para mexico

Código:
function formatPhone(id){
    //webrek
    var valor = document.getElementById(id).value;
    if(valor.length == 2 && valor == '55' || valor == '81' || valor == '33'){
        document.getElementById(id).value = '('+valor+')';
    }else if(valor.length == 3){
        document.getElementById(id).value = '('+valor+')';
    }
    if(valor.length == 8){
        document.getElementById(id).value = valor+'-';
    }  
}
Código HTML:
<input type="text" name="tel" id="tel"  size="50" onkeyup="formatPhone(this.id)" maxlength="13" />