-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformvalidate.js
356 lines (282 loc) · 4.08 KB
/
formvalidate.js
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
function firvalidate()
{
alert("hello User");
var check = document.getElementsByClassName('check');
var fname = document.fir.fname.value;
var lname = document.fir.lname.value;
var mob = document.fir.mob.value;
var email = document.fir.email.value;
var checkgen = document.getElementsByClassName('checkgen');
var date = new Date(document.fir.hdate.value);
var location = document.fir.location.value;
var pincode = document.fir.pincode.value;
var city = document.fir.city.value;
var states = document.fir.states.value;
var country = document.fir.country.value;
var desc = document.fir.desc.value;
var person = document.fir.person.value;
var file = document.fir.file.value;
var agree = document.fir.agree;
if(chcrime(check))
{
if(chname(fname, lname))
{
if(chmob(mob))
{
if(chemail(email))
{
if(chgender(checkgen))
{
if(chdate(date))
{
if(chlocation(location))
{
if(chpincode(pincode))
{
if(chcity(city))
{
if(chstates(states))
{
if(chcountry(country))
{
if(chdesc(desc))
{
if(chperson(person))
{
if(chfile(file))
{
if(chagree(agree))
{
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return false;
}
function chcrime(check)
{
x=0;
for( i=0; i<4; i++)
{
if(check[i].checked === true)
{
x++;
}
}
if(x==0)
{
alert('Please Select Incident Type');
c1.focus();
c2.focus();
c3.focus();
c4.focus();
return false;
}
else
{
return true;
}
}
function chname(fname, lname)
{
var fnlen = fname.length;
var lnlen = lname.length;
if (fnlen == 0 || lnlen == 0 || fnlen >= 12 || fnlen < 2 || lnlen >= 12 || lnlen <3)
{
alert("Please check first name and last name");
fname.focus();
lname.focus();
return false;
}
return true;
}
function chmob(mob)
{
var phoneno = /^\d{10}$/;
if(mob.match(phoneno))
{
return true;
}
else
{
alert("Please check phone number");
mob.focus();
return false;
}
}
function chemail(email)
{
var mailformat = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gm;
if(email.match(mailformat))
{
return true;
}
else
{
alert("You have entered an invalid email address!");
email.focus();
return false;
}
}
function chgender(checkgen)
{
x=0;
for( i=0; i<3; i++)
{
if(checkgen[i].checked === true)
{
x++;
}
}
if(x==0)
{
alert('Please Select Gender');
mgender.focus();
fgender.focus();
ogender.focus();
return false;
}
else
{
return true;
}
}
function chdate(date)
{
if(date.getFullYear() > 2020)
{
alert("Please check date");
date.focus();
return false;
}
return true;
}
function chlocation(location)
{
var letters = /^[a-zA-Z0-9\s,.'-]{3,}$/;
if(location.match(letters))
{
return true;
}
else
{
alert('Location must have alphanumeric characters only');
location.focus();
return false;
}
}
function chpincode(pincode)
{
var numbers = /^[0-9]+$/;
if(pincode.match(numbers))
{
return true;
}
else
{
alert('pin code must have numeric characters only');
pincode.focus();
return false;
}
}
function chcity(city)
{
var citylen = city.length;
if (citylen == 0 || citylen >= 12 || citylen < 3)
{
alert("Please check city");
city.focus();
return false;
}
return true;
}
function chstates(states)
{
if(states == "default")
{
alert('Select your state from the list');
states.focus();
return false;
}
else
{
return true;
}
}
function chcountry(country)
{
var countrylen = country.length;
if (countrylen == 0 || countrylen >= 12 || countrylen < 3)
{
alert("Please check country");
country.focus();
return false;
}
return true;
}
function chdesc(desc)
{
var desclen = desc.length;
if (desclen == 0 || desclen < 10)
{
alert("Please describe complaint properly");
desc.focus();
return false;
}
return true;
}
function chperson(person)
{
if (person == 0 || person >= 20 )
{
alert("Please check number of person ");
person.focus();
return false;
}
return true;
}
function chfile(file)
{
var fileextension = /(\.jpg|\.pdf|\.jpeg|\.png|\.gif)$/i;
if(!fileextension.exec(file))
{
alert('Please upload file having extensions .jpeg/\.pdf|.jpg/.png/.gif');
fileInput.value = '';
return false;
}
else
{
return true;
}
}
function chagree(agree)
{
x=0;
if(agree.checked)
{
x++;
}
if(x==0)
{
alert('Please agree the terms and condition');
agree.focus();
return false;
}
else
{
alert('FIR Form Submitted Successfully');
window.location.reload()
return true;
}
}