forked from CodeYourFuture/Module-Onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
88 lines (73 loc) · 2.12 KB
/
index.html
File metadata and controls
88 lines (73 loc) · 2.12 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>T-Shirt Order</title>
</head>
<body>
<form id="tshirtForm">
<label>
Full Name:
<input type="text" id="name">
</label>
<br><br>
<label>
Email:
<input type="text" id="email">
</label>
<br><br>
<label>
T-shirt Colour:
<select id="colour">
<option value="">Select a colour</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="black">Black</option>
</select>
</label>
<br><br>
<fieldset>
<legend>T-shirt Size</legend>
<label><input type="radio" name="size" value="XS"> XS</label><br>
<label><input type="radio" name="size" value="S"> S</label><br>
<label><input type="radio" name="size" value="M"> M</label><br>
<label><input type="radio" name="size" value="L"> L</label><br>
<label><input type="radio" name="size" value="XL"> XL</label><br>
<label><input type="radio" name="size" value="XXL"> XXL</label>
</fieldset>
<br>
<button type="submit">Submit</button>
</form>
<script>
document.getElementById("tshirtForm").addEventListener("submit", function (event) {
event.preventDefault();
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const colour = document.getElementById("colour").value;
const size = document.querySelector('input[name="size"]:checked');
const namePattern = /^[A-Za-z\s]{2,}$/; //I added this to validate names to accept only letter and spaces
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Basic email pattern validation
if (!namePattern.test(name)) {
alert("Please enter a valid name (letters and spaces only).");
return;
}
if (!emailPattern.test(email)) {
alert("Please enter a valid email address.");
return;
}
if (colour === "") {
alert("Please select a t-shirt colour.");
return;
}
if (!size) {
alert("Please select a t-shirt size.");
return;
}
alert("Order details are valid!");
});
</script>
<footer>
<h2>By Shuheda Begum</h2>
</footer>
</body>
</html>