-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
46 lines (42 loc) · 1.48 KB
/
index.html
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
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">
<h1>Phone Validator</h1>
</div>
<p>Este algoritmo irá testar se o número é uma sequência, se os números inseridos são intercalados e se é uma sequência de 3 números.</p>
<small>
<i>(Campo não tem máscara)</i>
</small>
<div class="form-group">
<input type="text" name="phoneNumber" id="phone" placeholder="Insira o telefone">
<div id="error">
</div>
</div>
<script src="index.js"></script>
<script>
var phone = document.getElementById('phone');
var errorMessage = '<span id="error">Telefone inválido!<span>';
phone.addEventListener('input', event => {
var value = event.target.value;
if (value.length > 11) {
event.target.value = value.split('').splice(0, 10).join('');
}
if ( !PhoneValidator.isValid(value) ) {
document.querySelector('#error').innerHTML = errorMessage;
} else {
if (document.querySelector('#error').childNodes.length) {
document.querySelector('#error').firstChild.remove();
}
}
});
</script>
</body>
</html>