-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart3_6.html
More file actions
84 lines (79 loc) · 2.94 KB
/
Copy pathpart3_6.html
File metadata and controls
84 lines (79 loc) · 2.94 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Phone Number Formatter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: grey;
color: white;
text-align: center;
padding: 20px;
}
input, button {
margin-top: 10px;
padding: 10px;
border-radius: 5px;
border: none;
}
button {
background-color: pink;
cursor: pointer;
}
button:hover {
background-color: #ff69b4;
}
#result {
margin-top: 20px;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>
</head>
<body>
<h1>Phone Number Splitter</h1>
<form id="phoneNumberForm">
<input type="text" id="phoneNumberInput" placeholder="(999) 999-9999"><br>
<button type="button" onclick="splitPhoneNumber()">Format</button>
<button type="button" onclick="clearForm()">Clear</button>
</form>
<div id="result">
<input type="text" id="areaCode" placeholder="Area Code" readonly>
<input type="text" id="firstThree" placeholder="First 3 Digits" readonly>
<input type="text" id="lastFour" placeholder="Last 4 Digits" readonly>
</div>
<p id="errorMessage"></p>
<a href="homework6.html" style="color: pink;">Back to Main Page of Homework 6</a>
<script>
$(document).ready(function(){
$('#phoneNumberInput').mask('(000) 000-0000');
});
function splitPhoneNumber() {
const phoneNumber = document.getElementById('phoneNumberInput').value;
const regex = /^\((\d{3})\) (\d{3})-(\d{4})$/;
const match = phoneNumber.match(regex);
if (match) {
document.getElementById('areaCode').value = match[1];
document.getElementById('firstThree').value = match[2];
document.getElementById('lastFour').value = match[3];
document.getElementById('errorMessage').textContent = '';
} else {
document.getElementById('errorMessage').textContent = 'Please enter the phone number in the format (999) 999-9999.';
clearResultFields();
}
}
function clearForm() {
document.getElementById('phoneNumberInput').value = '';
clearResultFields();
document.getElementById('errorMessage').textContent = '';
}
function clearResultFields() {
document.getElementById('areaCode').value = '';
document.getElementById('firstThree').value = '';
document.getElementById('lastFour').value = '';
}
</script>
</body>
</html>