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