-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (38 loc) · 1.22 KB
/
script.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
function formatarNumeroTelefone(input) {
if (!input) {
throw new Error("Input is null or undefined");
}
let numeroTelefone = input.value;
let numeroTelefoneFormatado = "";
if (numeroTelefone.length = 0) {
numeroTelefoneFormatado += "(";
}
if (numeroTelefone.length = 2) {
numeroTelefoneFormatado += numeroTelefone.substring(0, 2) + ") ";
}
if (numeroTelefone.length = 7) {
numeroTelefoneFormatado += numeroTelefone.substring(2, 7) + "-";
}
if (numeroTelefone.length = 7) {
numeroTelefoneFormatado += numeroTelefone.substring(7);
}
input.value = numeroTelefoneFormatado;
}
*/
// Função para mostrar/ocultar 'formato-aviso' do padrão 'telefone'
var telefoneInput = document.getElementById('telefone');
var formatoAviso = document.getElementById('formato-aviso');
var contagemErro = 0;
telefoneInput.addEventListener('input', function() {
if (!this.validity.valid) {
contagemErro++;
} else {
contagemErro = 0;
}
if (contagemErro >= 11) {
formatoAviso.style.display = 'block';
} else {
formatoAviso.style.display = 'none';
}
});