-
Notifications
You must be signed in to change notification settings - Fork 0
/
boom.php
42 lines (37 loc) · 1.21 KB
/
boom.php
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
<!DOCTYPE html>
<html>
<body>
<input onkeydown="phoneNumberFormatter()" id="phone-number" />
<script>
function formatPhoneNumber(value) {
if (!value) return value;
const phoneNumber = value.replace(/[^\d]/g, "");
const phoneNumberLength = phoneNumber.length;
if (phoneNumberLength < 4) return phoneNumber;
if (phoneNumberLength < 7) {
return `(${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3)}`;
}
return `(${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(
3,
6
)}-${phoneNumber.slice(6, 9)}`;
}
function phoneNumberFormatter() {
const inputField = document.getElementById("phone-number");
const formattedInputValue = formattPhoneNumber(inputField.value);
inputField.value = formattedInputValue;
}
</script>
<script>
if (string)(phone).length === 13; {
phone = string(phone).slice(1);
}
if (string)(phone).length === 10; {
phone = "254" + string(phone).slice(1);
}
elseif(string)(phone); {
phone = phone
}
</script>
</body>
</html>