-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformvalid.html
More file actions
160 lines (146 loc) · 5.02 KB
/
Copy pathformvalid.html
File metadata and controls
160 lines (146 loc) · 5.02 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<html>
<head>
<title>Registration Form</title>
<style>
body {
background-color: Azure;
font-family: Arial, sans-serif;
}
h1 {
text-align: center;
color: MidnightBlue;
}
form {
width: 40%; /* Reduced the width */
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 10px;
}
label {
font-weight: bold;
color: DarkSlateGray;
}
input, select {
width: 100%;
margin: 10px 0;
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
.inline-group {
display: flex;
align-items: center;
gap: 10px; /* Reduced the gap */
margin: 10px 0;
}
button {
background-color: MediumSeaGreen;
color: white;
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: ForestGreen;
}
</style>
<script>
function validateForm() {
let pwd = document.getElementById("pass").value;
let cpwd = document.getElementById("cpass").value;
let phone = document.getElementById("num").value;
let n = document.getElementById("text1").value;
let m = document.getElementById("text2").value;
let add = document.getElementById("text3").value;
let gend = document.querySelector('input[name="gen"]:checked');
if (n === "") {
alert("Please enter your first name");
return false;
}
if (m === "") {
alert("Please enter your last name");
return false;
}
if (add === "") {
alert("Please enter your address");
return false;
}
if (!gend) {
alert("Please select your gender");
return false;
}
if (pwd.length != 6) {
alert("Password must be exactly 6 characters long.");
return false;
}
if (pwd !== cpwd) {
alert("Passwords do not match.");
return false;
}
if (phone.length != 10 || isNaN(phone)) {
alert("Phone number must be exactly 10 digits.");
return false;
}
alert("Your data is submitted!");
return true;
}
</script>
</head>
<body>
<h1>Sample Registration Form</h1>
<form action="SUBMIT.HTML" onsubmit="return validateForm()">
<h4>Personal Information</h4>
<label>First name:</label>
<input type="text" name="text1" id="text1" placeholder="First Name">
<br>
<label>Last name:</label>
<input type="text" name="text2" id="text2" placeholder="Last Name">
<br>
<label>Address:</label>
<input type="text" name="text3" id="text3" placeholder="Your Address">
<br>
<label>Birth date:</label>
<input type="date">
<br>
<label>Email:</label>
<input type="email" placeholder="Enter your email">
<br>
<label for="pass">Password (exactly 6 characters):</label>
<input type="password" id="pass" name="pass" placeholder="Enter your password" maxlength="6">
<br>
<label for="cpass">Confirm Password:</label>
<input type="password" id="cpass" name="cpass" placeholder="Confirm your password" maxlength="6">
<br>
<label for="num">Contact details:</label>
<input type="text" id="num" name="num" placeholder="Enter your number" maxlength="10">
<br>
<div class="inline-group">
<label>Gender:</label>
<input type="radio" name="gen" value="Male"> Male
<input type="radio" name="gen" value="Female"> Female
</div>
<div class="inline-group">
<label>Branch:</label>
<input type="checkbox" name="branch" value="CMPN"> CMPN
<input type="checkbox" name="branch" value="IT"> IT
<input type="checkbox" name="branch" value="ECS"> ECS
<input type="checkbox" name="branch" value="EXTC"> EXTC
<input type="checkbox" name="branch" value="MEC"> MEC
</div>
<label>Select Your State:</label>
<select name="select">
<option value="">Select your state</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Delhi">Delhi</option>
<option value="Kerala">Kerala</option>
<option value="Karnataka">Karnataka</option>
</select>
<br>
<button type="submit" name="b1">Submit</button>
<button type="reset" name="b2">Reset</button>
</form>
</body>
</html>