-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
112 lines (98 loc) · 2.7 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
<head>
<title>Phone Dialer</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.container {
max-width: 450px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
border-radius: 4px;
}
.phone-container {
margin-bottom: 20px;
text-align: center;
}
.phone-button {
display: inline-block;
width: 40px;
height: 40px;
margin: 5px;
text-align: center;
line-height: 40px;
border: 1px solid #ccc;
border-radius: 50%;
cursor: pointer;
background-color: #f2f2f2;
transition: background-color 0.3s ease;
}
.phone-button:hover {
background-color: #e0e0e0;
}
.display {
margin-top: 20px;
padding: 10px;
font-size: 18px;
text-align: center;
border: 2px solid #211f1f;
width: 95%;
border-radius: 4px;
}
.valid {
color: green;
}
.invalid {
color: red;
}
</style>
</head>
<body>
<div class="container">
<div class="phone-container">
<h1>Phone number</h1>
</div>
<div class="phone-container">
<div class="display" id="display"></div>
</div>
<div class="phone-container">
<div class="phone-button" onclick="appendNumber('0')">0</div>
<div class="phone-button" onclick="appendNumber('1')">1</div>
<div class="phone-button" onclick="appendNumber('2')">2</div>
<div class="phone-button" onclick="appendNumber('3')">3</div>
<div class="phone-button" onclick="appendNumber('4')">4</div>
<div class="phone-button" onclick="appendNumber('5')">5</div>
<div class="phone-button" onclick="appendNumber('6')">6</div>
<div class="phone-button" onclick="appendNumber('7')">7</div>
<div class="phone-button" onclick="appendNumber('8')">8</div>
<div class="phone-button" onclick="appendNumber('9')">9</div>
</div>
</div>
<script>
function appendNumber(number) {
var display = document.getElementById('display');
var currentNumber = display.innerText;
// Replace '00' with '+'
if (currentNumber === '00') {
currentNumber = '+';
}
// Append the pressed number
currentNumber += number;
display.innerText = currentNumber;
// Validate the number format
if (currentNumber.match(/^\+[\d]{1,3}[\d]{10}$/)) {
display.classList.remove('invalid');
display.classList.add('valid');
} else {
display.classList.remove('valid');
display.classList.add('invalid');
}
}
</script>
</body>
</html>