-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask-9.html
More file actions
120 lines (109 loc) · 3.85 KB
/
Task-9.html
File metadata and controls
120 lines (109 loc) · 3.85 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS task9</title>
<link rel="stylesheet" href="Task-9_style.css">
</head>
<body>
<div class="container">
<form name="registration" class="registartion-form" onsubmit="return formValidation()">
<table>
<tr>
<td><label for="name">Name:</label></td>
<td><input type="text" name="name" id="name" placeholder="your name"></td>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td><input type="text" name="email" id="email" placeholder="your email"></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><label for="phoneNumber">Phone Number:</label></td>
<td><input type="number" name="phoneNumber" id="phoneNumber"></td>
</tr>
<tr>
<td><label for="gender">Gender:</label></td>
<td>Male: <input type="radio" name="gender" value="male">
Female: <input type="radio" name="gender" value="female">
Other: <input type="radio" name="gender" value="other"></td>
</tr>
<tr>
<td><label for="language">language</label></td>
<td>
<select name="language" id="language">
<option value="">Select language</option>
<option value="English">English</option>
<option value="Spanish">Telugu</option>
<option value="Hindi">Hindi</option>
<option value="Arabic">Tamil</option>
<option value="Russian">Russian</option>
</select>
</td>
</tr>
<tr>
<td><label for="zipcode">Zip Code:</label></td>
<td><input type="number" name="zipcode" id="zipcode"></td>
</tr>
<tr>
<td><label for="about">About:</label></td>
<td><textarea name="about" id="about" placeholder="Write about yourself..."></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="submit" value="Register" /></td>
</tr>
</table>
</form>
<script>
const name = document.getElementById("name");
const email = document.getElementById("email");
const password = document.getElementById("password");
const phoneNumber = document.getElementById("phoneNumber");
const gender = document.registration;
const language = document.getElementById("language");
const zipcode = document.getElementById("zipcode");
function formValidation() {
if (name.value.length < 2 || name.value.length > 20) {
alert("Name length should be more than 2 and less than 21");
name.focus();
return false;
}
if (email.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) {
alert("Please enter a valid email!");
email.focus();
return false;
}
if (!password.value.match(/^.{5,15}$/)) {
alert("Password length must be between 5-15 characters!");
password.focus();
return false;
}
if (!phoneNumber.value.match(/^[1-9][0-9]{9}$/)) {
alert("Phone number must be 10 characters long number and first digit can't be 0!");
phoneNumber.focus();
return false;
}
if (gender.gender.value === "") {
alert("Please select your gender!");
return false;
}
if (language.value === "") {
alert("Please select your language!")
return false;
}
if (!zipcode.value.match(/^[0-9]{6}$/)) {
alert("Zip code must be 6 characters long number!");
zipcode.focus();
return false;
}
return true;
}
</script>
</div>
</body>
</html>