forked from codemistic/Web-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
222 lines (200 loc) · 6.94 KB
/
index.html
File metadata and controls
222 lines (200 loc) · 6.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
<head>
<title></title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<h1
class="text-green text-center font-weight-bold"
style="font-size: 40px;"
>
Form Validation Using JavaScript
</h1>
<h4 class="text-blue text-center font-weight-bold" style="font-size: 20px;">
Sign Up
</h4>
<div class="container">
<br />
<div class="col-lg-5 m-auto d-block">
<form action="#" onsubmit="return validation()" class="bg-light">
<div class="form-group">
<label for="name" class="font-weight-regular"> Name </label>
<input
type="text"
name="name"
class="form-control"
id="name"
autocomplete="off"
/>
<span id="Name" class="text-danger font-weight-regular"> </span>
</div>
<div class="form-group">
<label class="font-weight-regular"> Email </label>
<input
type="text"
name="email"
class="form-control"
id="emails"
autocomplete="off"
/>
<span id="emailids" class="text-danger font-weight-regular"> </span>
</div>
<div class="form-group">
<label for="user" class="font-weight-regular"> Username </label>
<input
type="text"
name="user"
class="form-control"
id="user"
autocomplete="off"
/>
<span id="username" class="text-danger font-weight-regular"> </span>
</div>
<div class="form-group">
<label class="font-weight-regular"> Password </label>
<input
type="password"
name="pass"
class="form-control"
id="pass"
autocomplete="off"
/>
<span id="passwords" class="text-danger font-weight-regular">
</span>
</div>
<div class="form-group">
<label class="font-weight-regular"> Confirm Password </label>
<input
type="password"
name="conpass"
class="form-control"
id="conpass"
autocomplete="off"
/>
<span id="confrmpass" class="text-danger font-weight-regular">
</span>
</div>
<div class="form-group">
<label class="font-weight-regular"> Mobile Number </label>
<input
type="text"
name="mobile"
class="form-control"
id="mobileNumber"
autocomplete="off"
/>
<span id="mobileno" class="text-danger font-weight-regular"> </span>
</div>
<input
type="submit"
name="submit"
value="Submit"
class="btn btn-primary"
autocomplete="off"
/>
<input
type="reset"
name="reset"
value="Reset"
class="btn btn-secondary"
autocomplete="off"
/>
   Already have an account?
<a href="login.html">Login</a>
</form>
<br /><br />
</div>
</div>
<script type="text/javascript">
function validation() {
var name = document.getElementById("name").value;
var user = document.getElementById("user").value;
var pass = document.getElementById("pass").value;
var confirmpass = document.getElementById("conpass").value;
var mobileNumber = document.getElementById("mobileNumber").value;
var emails = document.getElementById("emails").value;
if (name == "") {
document.getElementById("Name").innerHTML =
" ** Please fill the Name field";
return false;
}
if (emails == "") {
document.getElementById("emailids").innerHTML =
" ** Please fill the email id field";
return false;
}
if (emails.indexOf("@") <= 0) {
document.getElementById("emailids").innerHTML = " ** Invalid Email";
return false;
}
if (
emails.charAt(emails.length - 4) != "." &&
emails.charAt(emails.length - 3) != "."
) {
document.getElementById("emailids").innerHTML = " ** Invalid Email";
return false;
}
if (user == "") {
document.getElementById("username").innerHTML =
" ** Please fill the username field";
return false;
}
if (user.length <= 3 || user.length > 20) {
document.getElementById("username").innerHTML =
" ** Username lenght must be between 3 and 20";
return false;
}
if (!isNaN(user)) {
document.getElementById("username").innerHTML =
" ** only characters are allowed";
return false;
}
if (pass == "") {
document.getElementById("passwords").innerHTML =
" ** Please fill the password field";
return false;
}
if (pass.length <= 5 || pass.length > 20) {
document.getElementById("passwords").innerHTML =
" ** Passwords lenght must be between 5 and 20";
return false;
}
if (pass != confirmpass) {
document.getElementById("confrmpass").innerHTML =
" ** Password Mismatch";
return false;
}
if (confirmpass == "") {
document.getElementById("confrmpass").innerHTML =
" ** Please fill the confirmpassword field";
return false;
}
if (mobileNumber == "") {
document.getElementById("mobileno").innerHTML =
" ** Please fill the mobile NUmber field";
return false;
}
if (isNaN(mobileNumber)) {
document.getElementById("mobileno").innerHTML =
" ** user must write digits only not characters";
return false;
}
if (mobileNumber.length != 11) {
document.getElementById("mobileno").innerHTML =
" ** Mobile Number must be 11 digits only";
return false;
}
}
</script>
</body>
</html>