1
|
<%@ page language="java"%>
|
2
|
|
3
|
<!--
|
4
|
/**
|
5
|
* '$RCSfile$'
|
6
|
* Authors: Duane Costa
|
7
|
* Copyright: 2005 University of New Mexico and
|
8
|
* Regents of the University of California and the
|
9
|
* National Center for Ecological Analysis and Synthesis
|
10
|
* For Details: http://www.nceas.ucsb.edu/
|
11
|
*
|
12
|
* '$Author: costa $'
|
13
|
* '$Date: 2006-06-14 08:26:14 -0700 (Wed, 14 Jun 2006) $'
|
14
|
* '$Revision: 3005 $'
|
15
|
*
|
16
|
* This program is free software; you can redistribute it and/or modify
|
17
|
* it under the terms of the GNU General Public License as published by
|
18
|
* the Free Software Foundation; either version 2 of the License, or
|
19
|
* (at your option) any later version.
|
20
|
*
|
21
|
* This program is distributed in the hope that it will be useful,
|
22
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24
|
* GNU General Public License for more details.
|
25
|
*
|
26
|
* You should have received a copy of the GNU General Public License
|
27
|
* along with this program; if not, write to the Free Software
|
28
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
29
|
*
|
30
|
*/
|
31
|
-->
|
32
|
|
33
|
<%@ include file="settings.jsp"%>
|
34
|
<%@ include file="session_vars.jsp"%>
|
35
|
|
36
|
<html>
|
37
|
|
38
|
<head>
|
39
|
<link href="<%=relativeRoot%>/lter.css" rel="stylesheet" type="text/css">
|
40
|
<title>
|
41
|
LTER Data Catalog Login
|
42
|
</title>
|
43
|
<%
|
44
|
String loginFailure = (String) request.getParameter("loginFailure");
|
45
|
String loginFailureMessage = "";
|
46
|
|
47
|
if ((loginFailure != null) && (loginFailure.equals("true"))) {
|
48
|
loginFailureMessage = "<p class=\"emphasis\">" +
|
49
|
"Login failed. " +
|
50
|
"Please enter a valid Username, Organization, and Password." +
|
51
|
"</p>";
|
52
|
}
|
53
|
%>
|
54
|
</head>
|
55
|
|
56
|
<body>
|
57
|
<form name="loginForm" method="POST" action="<%=relativeRoot%>/metacatloginforward.jsp" target="_top" onsubmit="return validateLoginForm(this)">
|
58
|
<table cellpadding="4" cellspacing="0">
|
59
|
<tr>
|
60
|
<td colspan="3" align="left">
|
61
|
<h2>
|
62
|
LTER Data Catalog Login
|
63
|
</h2>
|
64
|
Logging into your account enables you to search any additional, non-public data for which you may have access privileges.
|
65
|
<br />
|
66
|
<%=loginFailureMessage%>
|
67
|
</td>
|
68
|
<td>
|
69
|
|
70
|
</td>
|
71
|
</tr>
|
72
|
|
73
|
<tr>
|
74
|
<td align="right">
|
75
|
Username:
|
76
|
</td>
|
77
|
<td align="left">
|
78
|
<input type="text" name="username" maxlength="15" size="15" value="">
|
79
|
</td>
|
80
|
<td>
|
81
|
<a target="_top" href="http://knb.ecoinformatics.org/cgi-bin/ldapweb.cgi?cfg=lter">
|
82
|
Create a new account
|
83
|
</a>
|
84
|
</td>
|
85
|
</tr>
|
86
|
|
87
|
<tr>
|
88
|
<td align="right">
|
89
|
Organization:
|
90
|
</td>
|
91
|
<td align="left">
|
92
|
<select name="organization">
|
93
|
<option value="KU">
|
94
|
KU
|
95
|
</option>
|
96
|
<option value="LTER" selected="selected">
|
97
|
LTER
|
98
|
</option>
|
99
|
<option value="NCEAS">
|
100
|
NCEAS
|
101
|
</option>
|
102
|
<option value="OBFS">
|
103
|
OBFS
|
104
|
</option>
|
105
|
<option value="PISCO">
|
106
|
PISCO
|
107
|
</option>
|
108
|
<option value="SDSC">
|
109
|
SDSC
|
110
|
</option>
|
111
|
<option value="UCNRS">
|
112
|
UCNRS
|
113
|
</option>
|
114
|
<option value="unaffiliated">
|
115
|
unaffiliated
|
116
|
</option>
|
117
|
</select>
|
118
|
</td>
|
119
|
<td>
|
120
|
<a target="_top" href="http://knb.ecoinformatics.org/cgi-bin/ldapweb.cgi?stage=resetpass&cfg=lter">
|
121
|
Forgot your password?
|
122
|
</a>
|
123
|
</td>
|
124
|
</tr>
|
125
|
|
126
|
<tr>
|
127
|
<td align="right">
|
128
|
Password:
|
129
|
</td>
|
130
|
<td align="left">
|
131
|
<!-- Don't redisplay password for security reasons -->
|
132
|
<input type="password" name="password" maxlength="15" size="15" value="">
|
133
|
</td>
|
134
|
<td>
|
135
|
<a target="_top" href="http://knb.ecoinformatics.org/cgi-bin/ldapweb.cgi?stage=changepass&cfg=lter">
|
136
|
Change your password
|
137
|
</a>
|
138
|
</td>
|
139
|
</tr>
|
140
|
|
141
|
<tr>
|
142
|
<td>
|
143
|
|
144
|
</td>
|
145
|
<td align="left">
|
146
|
<input type="submit" value="Login">
|
147
|
|
148
|
<input type="reset" value="Reset">
|
149
|
</td>
|
150
|
<td>
|
151
|
|
152
|
</td>
|
153
|
</tr>
|
154
|
</table>
|
155
|
</form>
|
156
|
|
157
|
<script type="text/javascript" language="JavaScript">
|
158
|
<!--
|
159
|
var focusControl = document.forms["loginForm"].elements["username"];
|
160
|
|
161
|
if (focusControl.type != "hidden" && !focusControl.disabled) {
|
162
|
focusControl.focus();
|
163
|
}
|
164
|
// -->
|
165
|
</script>
|
166
|
|
167
|
<script type="text/javascript" language="Javascript1.1">
|
168
|
<!-- Begin
|
169
|
|
170
|
var bCancel = false;
|
171
|
|
172
|
function validateLoginForm(form) {
|
173
|
if (bCancel)
|
174
|
return true;
|
175
|
else
|
176
|
var formValidationResult;
|
177
|
formValidationResult = validateRequired(form) && validateMinLength(form);
|
178
|
return (formValidationResult == 1);
|
179
|
}
|
180
|
|
181
|
function loginForm_required () {
|
182
|
this.a0 = new Array("username", "Username is required.", new Function ("varName", " return this[varName];"));
|
183
|
this.a1 = new Array("password", "Password is required.", new Function ("varName", "this.minlength='3'; return this[varName];"));
|
184
|
}
|
185
|
|
186
|
function loginForm_minlength () {
|
187
|
this.a0 = new Array("password", "Password can not be less than 3 characters.", new Function ("varName", "this.minlength='3'; return this[varName];"));
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* Check to see if fields are in a valid float range.
|
192
|
* Fields are not checked if they are disabled.
|
193
|
* <p>
|
194
|
* @param form The form validation is taking place on.
|
195
|
*/
|
196
|
function validateFloatRange(form) {
|
197
|
var isValid = true;
|
198
|
var focusField = null;
|
199
|
var i = 0;
|
200
|
var fields = new Array();
|
201
|
var formName = form.getAttributeNode("name");
|
202
|
|
203
|
oRange = eval('new ' + formName.value + '_floatRange()');
|
204
|
for (x in oRange) {
|
205
|
var field = form[oRange[x][0]];
|
206
|
|
207
|
if ((field.type == 'hidden' ||
|
208
|
field.type == 'text' || field.type == 'textarea') &&
|
209
|
(field.value.length > 0) &&
|
210
|
field.disabled == false) {
|
211
|
|
212
|
var fMin = parseFloat(oRange[x][2]("min"));
|
213
|
var fMax = parseFloat(oRange[x][2]("max"));
|
214
|
var fValue = parseFloat(field.value);
|
215
|
if (!(fValue >= fMin && fValue <= fMax)) {
|
216
|
if (i == 0) {
|
217
|
focusField = field;
|
218
|
}
|
219
|
fields[i++] = oRange[x][1];
|
220
|
isValid = false;
|
221
|
}
|
222
|
}
|
223
|
}
|
224
|
if (fields.length > 0) {
|
225
|
focusField.focus();
|
226
|
alert(fields.join('\n'));
|
227
|
}
|
228
|
return isValid;
|
229
|
}
|
230
|
|
231
|
|
232
|
/**
|
233
|
* This is a place holder for common utilities used across the javascript validation
|
234
|
*
|
235
|
**/
|
236
|
|
237
|
/**
|
238
|
* Check to see if fields are a valid byte.
|
239
|
* Fields are not checked if they are disabled.
|
240
|
* <p>
|
241
|
* @param form The form validation is taking place on.
|
242
|
*/
|
243
|
function validateByte(form) {
|
244
|
var bValid = true;
|
245
|
var focusField = null;
|
246
|
var i = 0;
|
247
|
var fields = new Array();
|
248
|
var formName = form.getAttributeNode("name");
|
249
|
oByte = eval('new ' + formName.value + '_ByteValidations()');
|
250
|
|
251
|
for (x in oByte) {
|
252
|
var field = form[oByte[x][0]];
|
253
|
|
254
|
if ((field.type == 'hidden' ||
|
255
|
field.type == 'text' ||
|
256
|
field.type == 'textarea' ||
|
257
|
field.type == 'select-one' ||
|
258
|
field.type == 'radio') &&
|
259
|
field.disabled == false) {
|
260
|
|
261
|
var value = '';
|
262
|
// get field's value
|
263
|
if (field.type == "select-one") {
|
264
|
var si = field.selectedIndex;
|
265
|
if (si >= 0) {
|
266
|
value = field.options[si].value;
|
267
|
}
|
268
|
} else {
|
269
|
value = field.value;
|
270
|
}
|
271
|
|
272
|
if (value.length > 0) {
|
273
|
if (!isAllDigits(value)) {
|
274
|
bValid = false;
|
275
|
if (i == 0) {
|
276
|
focusField = field;
|
277
|
}
|
278
|
fields[i++] = oByte[x][1];
|
279
|
|
280
|
} else {
|
281
|
|
282
|
var iValue = parseInt(value);
|
283
|
if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
|
284
|
if (i == 0) {
|
285
|
focusField = field;
|
286
|
}
|
287
|
fields[i++] = oByte[x][1];
|
288
|
bValid = false;
|
289
|
}
|
290
|
}
|
291
|
}
|
292
|
|
293
|
}
|
294
|
}
|
295
|
if (fields.length > 0) {
|
296
|
focusField.focus();
|
297
|
alert(fields.join('\n'));
|
298
|
}
|
299
|
return bValid;
|
300
|
}
|
301
|
|
302
|
|
303
|
/**
|
304
|
* A field is considered valid if less than the specified maximum.
|
305
|
* Fields are not checked if they are disabled.
|
306
|
* <p>
|
307
|
* <strong>Caution:</strong> Using <code>validateMaxLength</code> on a password field in a
|
308
|
* login page gives unnecessary information away to hackers. While it only slightly
|
309
|
* weakens security, we suggest using it only when modifying a password.</p>
|
310
|
* @param form The form validation is taking place on.
|
311
|
*/
|
312
|
function validateMaxLength(form) {
|
313
|
var isValid = true;
|
314
|
var focusField = null;
|
315
|
var i = 0;
|
316
|
var fields = new Array();
|
317
|
var formName = form.getAttributeNode("name");
|
318
|
|
319
|
oMaxLength = eval('new ' + formName.value + '_maxlength()');
|
320
|
for (x in oMaxLength) {
|
321
|
var field = form[oMaxLength[x][0]];
|
322
|
|
323
|
if ((field.type == 'hidden' ||
|
324
|
field.type == 'text' ||
|
325
|
field.type == 'password' ||
|
326
|
field.type == 'textarea') &&
|
327
|
field.disabled == false) {
|
328
|
|
329
|
var iMax = parseInt(oMaxLength[x][2]("maxlength"));
|
330
|
if (field.value.length > iMax) {
|
331
|
if (i == 0) {
|
332
|
focusField = field;
|
333
|
}
|
334
|
fields[i++] = oMaxLength[x][1];
|
335
|
isValid = false;
|
336
|
}
|
337
|
}
|
338
|
}
|
339
|
if (fields.length > 0) {
|
340
|
focusField.focus();
|
341
|
alert(fields.join('\n'));
|
342
|
}
|
343
|
return isValid;
|
344
|
}
|
345
|
|
346
|
|
347
|
/**
|
348
|
* Check to see if fields must contain a value.
|
349
|
* Fields are not checked if they are disabled.
|
350
|
* <p>
|
351
|
* @param form The form validation is taking place on.
|
352
|
*/
|
353
|
function validateRequired(form) {
|
354
|
var isValid = true;
|
355
|
var focusField = null;
|
356
|
var i = 0;
|
357
|
var fields = new Array();
|
358
|
var formName = form.getAttributeNode("name");
|
359
|
|
360
|
oRequired = eval('new ' + formName.value + '_required()');
|
361
|
|
362
|
for (x in oRequired) {
|
363
|
var field = form[oRequired[x][0]];
|
364
|
|
365
|
if ((field.type == 'hidden' ||
|
366
|
field.type == 'text' ||
|
367
|
field.type == 'textarea' ||
|
368
|
field.type == 'file' ||
|
369
|
field.type == 'checkbox' ||
|
370
|
field.type == 'select-one' ||
|
371
|
field.type == 'password') &&
|
372
|
field.disabled == false) {
|
373
|
|
374
|
var value = '';
|
375
|
// get field's value
|
376
|
if (field.type == "select-one") {
|
377
|
var si = field.selectedIndex;
|
378
|
if (si >= 0) {
|
379
|
value = field.options[si].value;
|
380
|
}
|
381
|
} else if (field.type == 'checkbox') {
|
382
|
if (field.checked) {
|
383
|
value = field.value;
|
384
|
}
|
385
|
} else {
|
386
|
value = field.value;
|
387
|
}
|
388
|
|
389
|
if (trim(value).length == 0) {
|
390
|
|
391
|
if (i == 0) {
|
392
|
focusField = field;
|
393
|
}
|
394
|
fields[i++] = oRequired[x][1];
|
395
|
isValid = false;
|
396
|
}
|
397
|
} else if (field.type == "select-multiple") {
|
398
|
var numOptions = field.options.length;
|
399
|
lastSelected=-1;
|
400
|
for(loop=numOptions-1;loop>=0;loop--) {
|
401
|
if(field.options[loop].selected) {
|
402
|
lastSelected = loop;
|
403
|
value = field.options[loop].value;
|
404
|
break;
|
405
|
}
|
406
|
}
|
407
|
if(lastSelected < 0 || trim(value).length == 0) {
|
408
|
if(i == 0) {
|
409
|
focusField = field;
|
410
|
}
|
411
|
fields[i++] = oRequired[x][1];
|
412
|
isValid=false;
|
413
|
}
|
414
|
} else if ((field.length > 0) && (field[0].type == 'radio' || field[0].type == 'checkbox')) {
|
415
|
isChecked=-1;
|
416
|
for (loop=0;loop < field.length;loop++) {
|
417
|
if (field[loop].checked) {
|
418
|
isChecked=loop;
|
419
|
break; // only one needs to be checked
|
420
|
}
|
421
|
}
|
422
|
if (isChecked < 0) {
|
423
|
if (i == 0) {
|
424
|
focusField = field[0];
|
425
|
}
|
426
|
fields[i++] = oRequired[x][1];
|
427
|
isValid=false;
|
428
|
}
|
429
|
}
|
430
|
}
|
431
|
if (fields.length > 0) {
|
432
|
focusField.focus();
|
433
|
alert(fields.join('\n'));
|
434
|
}
|
435
|
return isValid;
|
436
|
}
|
437
|
|
438
|
// Trim whitespace from left and right sides of s.
|
439
|
function trim(s) {
|
440
|
return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
|
441
|
}
|
442
|
|
443
|
|
444
|
/**
|
445
|
* Check to see if fields are a valid integer.
|
446
|
* Fields are not checked if they are disabled.
|
447
|
* <p>
|
448
|
* @param form The form validation is taking place on.
|
449
|
*/
|
450
|
function validateInteger(form) {
|
451
|
var bValid = true;
|
452
|
var focusField = null;
|
453
|
var i = 0;
|
454
|
var fields = new Array();
|
455
|
var formName = form.getAttributeNode("name");
|
456
|
|
457
|
oInteger = eval('new ' + formName.value + '_IntegerValidations()');
|
458
|
for (x in oInteger) {
|
459
|
var field = form[oInteger[x][0]];
|
460
|
|
461
|
if ((field.type == 'hidden' ||
|
462
|
field.type == 'text' ||
|
463
|
field.type == 'textarea' ||
|
464
|
field.type == 'select-one' ||
|
465
|
field.type == 'radio') &&
|
466
|
field.disabled == false) {
|
467
|
|
468
|
var value = '';
|
469
|
// get field's value
|
470
|
if (field.type == "select-one") {
|
471
|
var si = field.selectedIndex;
|
472
|
if (si >= 0) {
|
473
|
value = field.options[si].value;
|
474
|
}
|
475
|
} else {
|
476
|
value = field.value;
|
477
|
}
|
478
|
|
479
|
if (value.length > 0) {
|
480
|
|
481
|
if (!isAllDigits(value)) {
|
482
|
bValid = false;
|
483
|
if (i == 0) {
|
484
|
focusField = field;
|
485
|
}
|
486
|
fields[i++] = oInteger[x][1];
|
487
|
|
488
|
} else {
|
489
|
var iValue = parseInt(value);
|
490
|
if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
|
491
|
if (i == 0) {
|
492
|
focusField = field;
|
493
|
}
|
494
|
fields[i++] = oInteger[x][1];
|
495
|
bValid = false;
|
496
|
}
|
497
|
}
|
498
|
}
|
499
|
}
|
500
|
}
|
501
|
if (fields.length > 0) {
|
502
|
focusField.focus();
|
503
|
alert(fields.join('\n'));
|
504
|
}
|
505
|
return bValid;
|
506
|
}
|
507
|
|
508
|
function isAllDigits(argvalue) {
|
509
|
argvalue = argvalue.toString();
|
510
|
var validChars = "0123456789";
|
511
|
var startFrom = 0;
|
512
|
if (argvalue.substring(0, 2) == "0x") {
|
513
|
validChars = "0123456789abcdefABCDEF";
|
514
|
startFrom = 2;
|
515
|
} else if (argvalue.charAt(0) == "0") {
|
516
|
validChars = "01234567";
|
517
|
startFrom = 1;
|
518
|
} else if (argvalue.charAt(0) == "-") {
|
519
|
startFrom = 1;
|
520
|
}
|
521
|
|
522
|
for (var n = startFrom; n < argvalue.length; n++) {
|
523
|
if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
|
524
|
}
|
525
|
return true;
|
526
|
}
|
527
|
|
528
|
|
529
|
/**
|
530
|
* Check to see if fields are a valid date.
|
531
|
* Fields are not checked if they are disabled.
|
532
|
* <p>
|
533
|
* @param form The form validation is taking place on.
|
534
|
*/
|
535
|
function validateDate(form) {
|
536
|
var bValid = true;
|
537
|
var focusField = null;
|
538
|
var i = 0;
|
539
|
var fields = new Array();
|
540
|
var formName = form.getAttributeNode("name");
|
541
|
|
542
|
oDate = eval('new ' + formName.value + '_DateValidations()');
|
543
|
|
544
|
for (x in oDate) {
|
545
|
var field = form[oDate[x][0]];
|
546
|
var value = field.value;
|
547
|
var datePattern = oDate[x][2]("datePatternStrict");
|
548
|
// try loose pattern
|
549
|
if (datePattern == null)
|
550
|
datePattern = oDate[x][2]("datePattern");
|
551
|
if ((field.type == 'hidden' ||
|
552
|
field.type == 'text' ||
|
553
|
field.type == 'textarea') &&
|
554
|
(value.length > 0) && (datePattern.length > 0) &&
|
555
|
field.disabled == false) {
|
556
|
var MONTH = "MM";
|
557
|
var DAY = "dd";
|
558
|
var YEAR = "yyyy";
|
559
|
var orderMonth = datePattern.indexOf(MONTH);
|
560
|
var orderDay = datePattern.indexOf(DAY);
|
561
|
var orderYear = datePattern.indexOf(YEAR);
|
562
|
if ((orderDay < orderYear && orderDay > orderMonth)) {
|
563
|
var iDelim1 = orderMonth + MONTH.length;
|
564
|
var iDelim2 = orderDay + DAY.length;
|
565
|
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
|
566
|
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
|
567
|
if (iDelim1 == orderDay && iDelim2 == orderYear) {
|
568
|
dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
|
569
|
} else if (iDelim1 == orderDay) {
|
570
|
dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
|
571
|
} else if (iDelim2 == orderYear) {
|
572
|
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
|
573
|
} else {
|
574
|
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
|
575
|
}
|
576
|
var matched = dateRegexp.exec(value);
|
577
|
if(matched != null) {
|
578
|
if (!isValidDate(matched[2], matched[1], matched[3])) {
|
579
|
if (i == 0) {
|
580
|
focusField = field;
|
581
|
}
|
582
|
fields[i++] = oDate[x][1];
|
583
|
bValid = false;
|
584
|
}
|
585
|
} else {
|
586
|
if (i == 0) {
|
587
|
focusField = field;
|
588
|
}
|
589
|
fields[i++] = oDate[x][1];
|
590
|
bValid = false;
|
591
|
}
|
592
|
} else if ((orderMonth < orderYear && orderMonth > orderDay)) {
|
593
|
var iDelim1 = orderDay + DAY.length;
|
594
|
var iDelim2 = orderMonth + MONTH.length;
|
595
|
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
|
596
|
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
|
597
|
if (iDelim1 == orderMonth && iDelim2 == orderYear) {
|
598
|
dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
|
599
|
} else if (iDelim1 == orderMonth) {
|
600
|
dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
|
601
|
} else if (iDelim2 == orderYear) {
|
602
|
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
|
603
|
} else {
|
604
|
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
|
605
|
}
|
606
|
var matched = dateRegexp.exec(value);
|
607
|
if(matched != null) {
|
608
|
if (!isValidDate(matched[1], matched[2], matched[3])) {
|
609
|
if (i == 0) {
|
610
|
focusField = field;
|
611
|
}
|
612
|
fields[i++] = oDate[x][1];
|
613
|
bValid = false;
|
614
|
}
|
615
|
} else {
|
616
|
if (i == 0) {
|
617
|
focusField = field;
|
618
|
}
|
619
|
fields[i++] = oDate[x][1];
|
620
|
bValid = false;
|
621
|
}
|
622
|
} else if ((orderMonth > orderYear && orderMonth < orderDay)) {
|
623
|
var iDelim1 = orderYear + YEAR.length;
|
624
|
var iDelim2 = orderMonth + MONTH.length;
|
625
|
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
|
626
|
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
|
627
|
if (iDelim1 == orderMonth && iDelim2 == orderDay) {
|
628
|
dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
|
629
|
} else if (iDelim1 == orderMonth) {
|
630
|
dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
|
631
|
} else if (iDelim2 == orderDay) {
|
632
|
dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
|
633
|
} else {
|
634
|
dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
|
635
|
}
|
636
|
var matched = dateRegexp.exec(value);
|
637
|
if(matched != null) {
|
638
|
if (!isValidDate(matched[3], matched[2], matched[1])) {
|
639
|
if (i == 0) {
|
640
|
focusField = field;
|
641
|
}
|
642
|
fields[i++] = oDate[x][1];
|
643
|
bValid = false;
|
644
|
}
|
645
|
} else {
|
646
|
if (i == 0) {
|
647
|
focusField = field;
|
648
|
}
|
649
|
fields[i++] = oDate[x][1];
|
650
|
bValid = false;
|
651
|
}
|
652
|
} else {
|
653
|
if (i == 0) {
|
654
|
focusField = field;
|
655
|
}
|
656
|
fields[i++] = oDate[x][1];
|
657
|
bValid = false;
|
658
|
}
|
659
|
}
|
660
|
}
|
661
|
if (fields.length > 0) {
|
662
|
focusField.focus();
|
663
|
alert(fields.join('\n'));
|
664
|
}
|
665
|
return bValid;
|
666
|
}
|
667
|
|
668
|
function isValidDate(day, month, year) {
|
669
|
if (month < 1 || month > 12) {
|
670
|
return false;
|
671
|
}
|
672
|
if (day < 1 || day > 31) {
|
673
|
return false;
|
674
|
}
|
675
|
if ((month == 4 || month == 6 || month == 9 || month == 11) &&
|
676
|
(day == 31)) {
|
677
|
return false;
|
678
|
}
|
679
|
if (month == 2) {
|
680
|
var leap = (year % 4 == 0 &&
|
681
|
(year % 100 != 0 || year % 400 == 0));
|
682
|
if (day>29 || (day == 29 && !leap)) {
|
683
|
return false;
|
684
|
}
|
685
|
}
|
686
|
return true;
|
687
|
}
|
688
|
|
689
|
|
690
|
/**
|
691
|
* Check to see if fields are a valid creditcard number based on Luhn checksum.
|
692
|
* Fields are not checked if they are disabled.
|
693
|
* <p>
|
694
|
* @param form The form validation is taking place on.
|
695
|
*/
|
696
|
function validateCreditCard(form) {
|
697
|
var bValid = true;
|
698
|
var focusField = null;
|
699
|
var i = 0;
|
700
|
var fields = new Array();
|
701
|
var formName = form.getAttributeNode("name");
|
702
|
|
703
|
oCreditCard = eval('new ' + formName.value + '_creditCard()');
|
704
|
|
705
|
for (x in oCreditCard) {
|
706
|
if ((form[oCreditCard[x][0]].type == 'text' ||
|
707
|
form[oCreditCard[x][0]].type == 'textarea') &&
|
708
|
(form[oCreditCard[x][0]].value.length > 0) &&
|
709
|
form[oCreditCard[x][0]].disabled == false) {
|
710
|
if (!luhnCheck(form[oCreditCard[x][0]].value)) {
|
711
|
if (i == 0) {
|
712
|
focusField = form[oCreditCard[x][0]];
|
713
|
}
|
714
|
fields[i++] = oCreditCard[x][1];
|
715
|
bValid = false;
|
716
|
}
|
717
|
}
|
718
|
}
|
719
|
if (fields.length > 0) {
|
720
|
focusField.focus();
|
721
|
alert(fields.join('\n'));
|
722
|
}
|
723
|
return bValid;
|
724
|
}
|
725
|
|
726
|
/**
|
727
|
* Checks whether a given credit card number has a valid Luhn checksum.
|
728
|
* This allows you to spot most randomly made-up or garbled credit card numbers immediately.
|
729
|
* Reference: http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html
|
730
|
*/
|
731
|
function luhnCheck(cardNumber) {
|
732
|
if (isLuhnNum(cardNumber)) {
|
733
|
var no_digit = cardNumber.length;
|
734
|
var oddoeven = no_digit & 1;
|
735
|
var sum = 0;
|
736
|
for (var count = 0; count < no_digit; count++) {
|
737
|
var digit = parseInt(cardNumber.charAt(count));
|
738
|
if (!((count & 1) ^ oddoeven)) {
|
739
|
digit *= 2;
|
740
|
if (digit > 9) digit -= 9;
|
741
|
};
|
742
|
sum += digit;
|
743
|
};
|
744
|
if (sum == 0) return false;
|
745
|
if (sum % 10 == 0) return true;
|
746
|
};
|
747
|
return false;
|
748
|
}
|
749
|
|
750
|
function isLuhnNum(argvalue) {
|
751
|
argvalue = argvalue.toString();
|
752
|
if (argvalue.length == 0) {
|
753
|
return false;
|
754
|
}
|
755
|
for (var n = 0; n < argvalue.length; n++) {
|
756
|
if ((argvalue.substring(n, n+1) < "0") ||
|
757
|
(argvalue.substring(n,n+1) > "9")) {
|
758
|
return false;
|
759
|
}
|
760
|
}
|
761
|
return true;
|
762
|
}
|
763
|
|
764
|
|
765
|
/**
|
766
|
* Check to see if fields is in a valid integer range.
|
767
|
* Fields are not checked if they are disabled.
|
768
|
* <p>
|
769
|
* @param form The form validation is taking place on.
|
770
|
*/
|
771
|
function validateIntRange(form) {
|
772
|
var isValid = true;
|
773
|
var focusField = null;
|
774
|
var i = 0;
|
775
|
var fields = new Array();
|
776
|
var formName = form.getAttributeNode("name");
|
777
|
|
778
|
oRange = eval('new ' + formName.value + '_intRange()');
|
779
|
for (x in oRange) {
|
780
|
var field = form[oRange[x][0]];
|
781
|
if (field.disabled == false) {
|
782
|
var value = '';
|
783
|
if (field.type == 'hidden' ||
|
784
|
field.type == 'text' || field.type == 'textarea' ||
|
785
|
field.type == 'radio' ) {
|
786
|
value = field.value;
|
787
|
}
|
788
|
if (field.type == 'select-one') {
|
789
|
var si = field.selectedIndex;
|
790
|
if (si >= 0) {
|
791
|
value = field.options[si].value;
|
792
|
}
|
793
|
}
|
794
|
if (value.length > 0) {
|
795
|
var iMin = parseInt(oRange[x][2]("min"));
|
796
|
var iMax = parseInt(oRange[x][2]("max"));
|
797
|
var iValue = parseInt(value);
|
798
|
if (!(iValue >= iMin && iValue <= iMax)) {
|
799
|
if (i == 0) {
|
800
|
focusField = field;
|
801
|
}
|
802
|
fields[i++] = oRange[x][1];
|
803
|
isValid = false;
|
804
|
}
|
805
|
}
|
806
|
}
|
807
|
}
|
808
|
if (fields.length > 0) {
|
809
|
focusField.focus();
|
810
|
alert(fields.join('\n'));
|
811
|
}
|
812
|
return isValid;
|
813
|
}
|
814
|
|
815
|
|
816
|
/**
|
817
|
* Check to see if fields are a valid short.
|
818
|
* Fields are not checked if they are disabled.
|
819
|
* <p>
|
820
|
* @param form The form validation is taking place on.
|
821
|
*/
|
822
|
function validateShort(form) {
|
823
|
var bValid = true;
|
824
|
var focusField = null;
|
825
|
var i = 0;
|
826
|
var fields = new Array();
|
827
|
var formName = form.getAttributeNode("name");
|
828
|
|
829
|
oShort = eval('new ' + formName.value + '_ShortValidations()');
|
830
|
|
831
|
for (x in oShort) {
|
832
|
var field = form[oShort[x][0]];
|
833
|
|
834
|
if ((field.type == 'hidden' ||
|
835
|
field.type == 'text' ||
|
836
|
field.type == 'textarea' ||
|
837
|
field.type == 'select-one' ||
|
838
|
field.type == 'radio') &&
|
839
|
field.disabled == false) {
|
840
|
|
841
|
var value = '';
|
842
|
// get field's value
|
843
|
if (field.type == "select-one") {
|
844
|
var si = field.selectedIndex;
|
845
|
if (si >= 0) {
|
846
|
value = field.options[si].value;
|
847
|
}
|
848
|
} else {
|
849
|
value = field.value;
|
850
|
}
|
851
|
|
852
|
if (value.length > 0) {
|
853
|
if (!isAllDigits(value)) {
|
854
|
bValid = false;
|
855
|
if (i == 0) {
|
856
|
focusField = field;
|
857
|
}
|
858
|
fields[i++] = oShort[x][1];
|
859
|
|
860
|
} else {
|
861
|
|
862
|
var iValue = parseInt(value);
|
863
|
if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
|
864
|
if (i == 0) {
|
865
|
focusField = field;
|
866
|
}
|
867
|
fields[i++] = oShort[x][1];
|
868
|
bValid = false;
|
869
|
}
|
870
|
}
|
871
|
}
|
872
|
}
|
873
|
}
|
874
|
if (fields.length > 0) {
|
875
|
focusField.focus();
|
876
|
alert(fields.join('\n'));
|
877
|
}
|
878
|
return bValid;
|
879
|
}
|
880
|
|
881
|
|
882
|
/**
|
883
|
* Check to see if fields are a valid float.
|
884
|
* Fields are not checked if they are disabled.
|
885
|
* <p>
|
886
|
* @param form The form validation is taking place on.
|
887
|
*/
|
888
|
function validateFloat(form) {
|
889
|
var bValid = true;
|
890
|
var focusField = null;
|
891
|
var i = 0;
|
892
|
var fields = new Array();
|
893
|
var formName = form.getAttributeNode("name");
|
894
|
|
895
|
oFloat = eval('new ' + formName.value + '_FloatValidations()');
|
896
|
for (x in oFloat) {
|
897
|
var field = form[oFloat[x][0]];
|
898
|
|
899
|
if ((field.type == 'hidden' ||
|
900
|
field.type == 'text' ||
|
901
|
field.type == 'textarea' ||
|
902
|
field.type == 'select-one' ||
|
903
|
field.type == 'radio') &&
|
904
|
field.disabled == false) {
|
905
|
|
906
|
var value = '';
|
907
|
// get field's value
|
908
|
if (field.type == "select-one") {
|
909
|
var si = field.selectedIndex;
|
910
|
if (si >= 0) {
|
911
|
value = field.options[si].value;
|
912
|
}
|
913
|
} else {
|
914
|
value = field.value;
|
915
|
}
|
916
|
|
917
|
if (value.length > 0) {
|
918
|
// remove '.' before checking digits
|
919
|
var tempArray = value.split('.');
|
920
|
//Strip off leading '0'
|
921
|
var zeroIndex = 0;
|
922
|
var joinedString= tempArray.join('');
|
923
|
while (joinedString.charAt(zeroIndex) == '0') {
|
924
|
zeroIndex++;
|
925
|
}
|
926
|
var noZeroString = joinedString.substring(zeroIndex,joinedString.length);
|
927
|
|
928
|
if (!isAllDigits(noZeroString)) {
|
929
|
bValid = false;
|
930
|
if (i == 0) {
|
931
|
focusField = field;
|
932
|
}
|
933
|
fields[i++] = oFloat[x][1];
|
934
|
|
935
|
} else {
|
936
|
var iValue = parseFloat(value);
|
937
|
if (isNaN(iValue)) {
|
938
|
if (i == 0) {
|
939
|
focusField = field;
|
940
|
}
|
941
|
fields[i++] = oFloat[x][1];
|
942
|
bValid = false;
|
943
|
}
|
944
|
}
|
945
|
}
|
946
|
}
|
947
|
}
|
948
|
if (fields.length > 0) {
|
949
|
focusField.focus();
|
950
|
alert(fields.join('\n'));
|
951
|
}
|
952
|
return bValid;
|
953
|
}
|
954
|
|
955
|
|
956
|
/**
|
957
|
* Check to see if fields are a valid email address.
|
958
|
* Fields are not checked if they are disabled.
|
959
|
* <p>
|
960
|
* @param form The form validation is taking place on.
|
961
|
*/
|
962
|
function validateEmail(form) {
|
963
|
var bValid = true;
|
964
|
var focusField = null;
|
965
|
var i = 0;
|
966
|
var fields = new Array();
|
967
|
var formName = form.getAttributeNode("name");
|
968
|
|
969
|
|
970
|
oEmail = eval('new ' + formName.value + '_email()');
|
971
|
|
972
|
for (x in oEmail) {
|
973
|
var field = form[oEmail[x][0]];
|
974
|
if ((field.type == 'hidden' ||
|
975
|
field.type == 'text' ||
|
976
|
field.type == 'textarea') &&
|
977
|
(field.value.length > 0) &&
|
978
|
field.disabled == false) {
|
979
|
if (!checkEmail(field.value)) {
|
980
|
if (i == 0) {
|
981
|
focusField = field;
|
982
|
}
|
983
|
fields[i++] = oEmail[x][1];
|
984
|
bValid = false;
|
985
|
}
|
986
|
}
|
987
|
}
|
988
|
if (fields.length > 0) {
|
989
|
focusField.focus();
|
990
|
alert(fields.join('\n'));
|
991
|
}
|
992
|
return bValid;
|
993
|
}
|
994
|
|
995
|
/**
|
996
|
* Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
|
997
|
* http://javascript.internet.com
|
998
|
*/
|
999
|
function checkEmail(emailStr) {
|
1000
|
if (emailStr.length == 0) {
|
1001
|
return true;
|
1002
|
}
|
1003
|
var emailPat=/^(.+)@(.+)$/;
|
1004
|
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
|
1005
|
var validChars="\[^\\s" + specialChars + "\]";
|
1006
|
var quotedUser="(\"[^\"]*\")";
|
1007
|
var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
|
1008
|
var atom=validChars + '+';
|
1009
|
var word="(" + atom + "|" + quotedUser + ")";
|
1010
|
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
|
1011
|
var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
|
1012
|
var matchArray=emailStr.match(emailPat);
|
1013
|
if (matchArray == null) {
|
1014
|
return false;
|
1015
|
}
|
1016
|
var user=matchArray[1];
|
1017
|
var domain=matchArray[2];
|
1018
|
if (user.match(userPat) == null) {
|
1019
|
return false;
|
1020
|
}
|
1021
|
var IPArray = domain.match(ipDomainPat);
|
1022
|
if (IPArray != null) {
|
1023
|
for (var i = 1; i <= 4; i++) {
|
1024
|
if (IPArray[i] > 255) {
|
1025
|
return false;
|
1026
|
}
|
1027
|
}
|
1028
|
return true;
|
1029
|
}
|
1030
|
var domainArray=domain.match(domainPat);
|
1031
|
if (domainArray == null) {
|
1032
|
return false;
|
1033
|
}
|
1034
|
var atomPat=new RegExp(atom,"g");
|
1035
|
var domArr=domain.match(atomPat);
|
1036
|
var len=domArr.length;
|
1037
|
if ((domArr[domArr.length-1].length < 2) ||
|
1038
|
(domArr[domArr.length-1].length > 3)) {
|
1039
|
return false;
|
1040
|
}
|
1041
|
if (len < 2) {
|
1042
|
return false;
|
1043
|
}
|
1044
|
return true;
|
1045
|
}
|
1046
|
|
1047
|
|
1048
|
/**
|
1049
|
* Check to see if fields are a valid using a regular expression.
|
1050
|
* Fields are not checked if they are disabled.
|
1051
|
* <p>
|
1052
|
* @param form The form validation is taking place on.
|
1053
|
*/
|
1054
|
function validateMask(form) {
|
1055
|
var isValid = true;
|
1056
|
var focusField = null;
|
1057
|
var i = 0;
|
1058
|
var fields = new Array();
|
1059
|
var formName = form.getAttributeNode("name");
|
1060
|
|
1061
|
oMasked = eval('new ' + formName.value + '_mask()');
|
1062
|
for (x in oMasked) {
|
1063
|
var field = form[oMasked[x][0]];
|
1064
|
|
1065
|
if ((field.type == 'hidden' ||
|
1066
|
field.type == 'text' ||
|
1067
|
field.type == 'textarea' ||
|
1068
|
field.type == 'file') &&
|
1069
|
(field.value.length > 0) &&
|
1070
|
field.disabled == false) {
|
1071
|
|
1072
|
if (!matchPattern(field.value, oMasked[x][2]("mask"))) {
|
1073
|
if (i == 0) {
|
1074
|
focusField = field;
|
1075
|
}
|
1076
|
fields[i++] = oMasked[x][1];
|
1077
|
isValid = false;
|
1078
|
}
|
1079
|
}
|
1080
|
}
|
1081
|
|
1082
|
if (fields.length > 0) {
|
1083
|
focusField.focus();
|
1084
|
alert(fields.join('\n'));
|
1085
|
}
|
1086
|
return isValid;
|
1087
|
}
|
1088
|
|
1089
|
function matchPattern(value, mask) {
|
1090
|
return mask.exec(value);
|
1091
|
}
|
1092
|
|
1093
|
|
1094
|
/**
|
1095
|
* A field is considered valid if greater than the specified minimum.
|
1096
|
* Fields are not checked if they are disabled.
|
1097
|
* <p>
|
1098
|
* <strong>Caution:</strong> Using <code>validateMinLength</code> on a password field in a
|
1099
|
* login page gives unnecessary information away to hackers. While it only slightly
|
1100
|
* weakens security, we suggest using it only when modifying a password.</p>
|
1101
|
* @param form The form validation is taking place on.
|
1102
|
*/
|
1103
|
function validateMinLength(form) {
|
1104
|
var isValid = true;
|
1105
|
var focusField = null;
|
1106
|
var i = 0;
|
1107
|
var fields = new Array();
|
1108
|
var formName = form.getAttributeNode("name");
|
1109
|
|
1110
|
|
1111
|
oMinLength = eval('new ' + formName.value + '_minlength()');
|
1112
|
|
1113
|
for (x in oMinLength) {
|
1114
|
var field = form[oMinLength[x][0]];
|
1115
|
|
1116
|
if ((field.type == 'hidden' ||
|
1117
|
field.type == 'text' ||
|
1118
|
field.type == 'password' ||
|
1119
|
field.type == 'textarea') &&
|
1120
|
field.disabled == false) {
|
1121
|
|
1122
|
var iMin = parseInt(oMinLength[x][2]("minlength"));
|
1123
|
if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
|
1124
|
if (i == 0) {
|
1125
|
focusField = field;
|
1126
|
}
|
1127
|
fields[i++] = oMinLength[x][1];
|
1128
|
isValid = false;
|
1129
|
}
|
1130
|
}
|
1131
|
}
|
1132
|
if (fields.length > 0) {
|
1133
|
focusField.focus();
|
1134
|
alert(fields.join('\n'));
|
1135
|
}
|
1136
|
return isValid;
|
1137
|
}
|
1138
|
|
1139
|
|
1140
|
//End -->
|
1141
|
</script>
|
1142
|
|
1143
|
</body>
|
1144
|
|
1145
|
</html>
|