JavaScript - web se vea igual en celular (formateo de texto en campo)

 
Vista:
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

web se vea igual en celular (formateo de texto en campo)

Publicado por Eduardo (173 intervenciones) el 02/12/2020 21:54:26
Hola este codigo muy amablemente me ayudó un gran amigo de este foro el cual hace que el texto se formatee a medida que se va escribiendo en el campo de la forma AAA-000

pero solo sirve si la web la veo en un PC y desde un Smartphone o celular no que se puede hacer para que haga lo mismo si la web es abierta desde un celular?

Mil gracias!!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
 
    Código (LLL-000): <input type="text" id="codigo" maxlength="7">
 
</body>
</html>
 
<script>
document.getElementById("codigo").addEventListener("keypress", function(e) {
    if (this.value.length<3 && /[A-Za-z]/.test(e.key)) {
        this.value+=e.key.toUpperCase();
    }
    if (this.value.length>=4 && /[A-Za-z0-9]/.test(e.key)) {
        return;
    }
    if (this.value.length==3) {
        this.value+="-";
    }
    e.preventDefault();
});
</script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder