-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp 9.txt
More file actions
93 lines (77 loc) · 2.27 KB
/
Copy pathexp 9.txt
File metadata and controls
93 lines (77 loc) · 2.27 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
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Validation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<form id="myForm">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<span id="emailError" class="error"></span>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone" required>
<span id="phoneError" class="error"></span>
<button type="submit">Submit</button>
</form>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/validator/13.6.0/validator.min.js"></script>
<script src="script.js"></script>
</body>
</html>
style.css */
body { font-family: Arial, sans-serif; background-color: #f4f4f4;
display: flex;
justify-content: center; align-items: center; height: 100vh; margin: 0;
}
.container {
background-color: white; padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
form { display: flex;
flex-direction: column;
}
label {
margin-bottom: 5px;
}
input {
margin-bottom: 10px; padding: 10px; border: 1px solid #ccc; border-radius: 3px;
}
button { padding: 10px;
background-color: #28a745; color: white;
border: none;
border-radius: 3px; cursor: pointer;
}
button:hover {
background-color: #218838;
} .error { color: red;
font-size: 0.875em;
}
javascript script.js */
document.getElementById('myForm').addEventListener('submit', function (e) {
e.preventDefault();
let email = document.getElementById('email').value;
let phone = document.getElementById('phone').value;
let emailError = document.getElementById('emailError');
let phoneError = document.getElementById('phoneError');
// Clear previous error messages
emailError.textContent = '';
phoneError.textContent = '';
// Validate email
if (!validator.isEmail(email)) {
emailError.textContent = 'Please enter a valid email address.';
}
// Validate phone number
if (!validator.isMobilePhone(phone, 'any')) {
phoneError.textContent = 'Please enter a valid phone number.';
}
// If no errors, submit the form (for demonstration purposes, we'll just log the values)
if (validator.isEmail(email) && validator.isMobilePhone(phone, 'any')) {
console.log('Email:', email);
console.log('Phone:', phone);
}
});