Revision 2760
Added by Duane Costa about 19 years ago
lib/style/skins/default/include_advancedsearch.jsp | ||
---|---|---|
61 | 61 |
return canSearch; |
62 | 62 |
} |
63 | 63 |
|
64 |
function keywordSearch(formObj, searchKeyword) { |
|
65 |
var searchString = trim(searchKeyword); |
|
66 |
if (searchString=="") searchString="%"; |
|
67 |
formObj.anyfield.value=searchString; |
|
68 |
formObj.submit(); |
|
69 |
return true; |
|
70 |
} |
|
71 |
|
|
72 | 64 |
function submitRequest(form) { |
73 | 65 |
var x_range = document.map.get_x_range(); |
74 | 66 |
var y_range = document.map.get_y_range(); |
... | ... | |
81 | 73 |
var y_lo = y_range.substring(0, y_index); |
82 | 74 |
var y_hi = y_range.substring(y_index + 1, y_length); |
83 | 75 |
|
84 |
// alert("xrange: " + x_range + " y_range: " + y_range); |
|
76 |
// Re-initialize the hidden form values prior to submitting |
|
77 |
document.advancedSearchForm.northBound.value = ""; |
|
78 |
document.advancedSearchForm.southBound.value = ""; |
|
79 |
document.advancedSearchForm.eastBound.value = ""; |
|
80 |
document.advancedSearchForm.westBound.value = ""; |
|
85 | 81 |
|
86 | 82 |
if ((x_range != "-180.0 180.0") && (y_range != "-90.0 90.0")) { |
87 | 83 |
document.advancedSearchForm.northBound.value = y_hi; |
... | ... | |
122 | 118 |
action="advancedsearchforward.jsp" |
123 | 119 |
onsubmit="return validateAdvancedSearchForm(this)" |
124 | 120 |
target="_top"> |
125 |
<table> |
|
121 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
|
|
126 | 122 |
<tr> |
127 | 123 |
<td colspan="2"><hr/></td> |
128 | 124 |
</tr> |
... | ... | |
347 | 343 |
<td> </td> |
348 | 344 |
<td> </td> |
349 | 345 |
</tr> |
346 |
|
|
347 |
<!-- |
|
348 |
Un-comment the following section to include an input box that allows the |
|
349 |
user to restrict the search to a specific LTER site. Obviously, this is |
|
350 |
probably useful only within LTER. |
|
351 |
--> |
|
352 |
|
|
353 |
<!-- |
|
350 | 354 |
<tr> |
351 | 355 |
<td colspan="2"><hr/></td> |
352 | 356 |
</tr> |
... | ... | |
398 | 402 |
<td> </td> |
399 | 403 |
<td> </td> |
400 | 404 |
</tr> |
405 |
--> |
|
401 | 406 |
<tr> |
402 | 407 |
<td colspan="2"><hr/></td> |
403 | 408 |
</tr> |
... | ... | |
442 | 447 |
<input type="hidden" name="eastBound" value=""/> |
443 | 448 |
<input type="hidden" name="westBound" value=""/> |
444 | 449 |
</form> |
450 |
<script type="text/javascript" language="Javascript1.1"> |
|
451 |
|
|
452 |
<!-- Begin JavaScript input validation checking code. |
|
453 |
|
|
454 |
var bCancel = false; |
|
455 |
|
|
456 |
function validateAdvancedSearchForm(form) { |
|
457 |
if (bCancel) |
|
458 |
return true; |
|
459 |
else |
|
460 |
var formValidationResult; |
|
461 |
formValidationResult = validateFloat(form) && validateFloatRange(form); |
|
462 |
return (formValidationResult == 1); |
|
463 |
} |
|
464 |
|
|
465 |
function advancedSearchForm_FloatValidations () { |
|
466 |
this.a0 = new Array("westBound", "West Boundary must be a number.", new Function ("varName", "this.min='-180.0'; this.max='180.0'; return this[varName];")); |
|
467 |
this.a1 = new Array("eastBound", "East Boundary must be a number.", new Function ("varName", "this.min='-180.0'; this.max='180.0'; return this[varName];")); |
|
468 |
this.a2 = new Array("northBound", "North Boundary must be a number.", new Function ("varName", "this.min='-90.0'; this.max='90.0'; return this[varName];")); |
|
469 |
this.a3 = new Array("southBound", "South Boundary must be a number.", new Function ("varName", "this.min='-90.0'; this.max='90.0'; return this[varName];")); |
|
470 |
} |
|
471 |
|
|
472 |
function advancedSearchForm_DateValidations () { |
|
473 |
this.a0 = new Array("startDate", "Start Date must be a date (YYYY-MM-DD).", new Function ("varName", "this.datePattern='yyyy-MM-dd'; return this[varName];")); |
|
474 |
this.a1 = new Array("endDate", "End Date must be a date (YYYY-MM-DD).", new Function ("varName", "this.datePattern='yyyy-MM-dd'; return this[varName];")); |
|
475 |
} |
|
476 |
|
|
477 |
function advancedSearchForm_floatRange () { |
|
478 |
this.a0 = new Array("westBound", "West Boundary must be in the range -180.0 through 180.0.", new Function ("varName", "this.min='-180.0'; this.max='180.0'; return this[varName];")); |
|
479 |
this.a1 = new Array("eastBound", "East Boundary must be in the range -180.0 through 180.0.", new Function ("varName", "this.min='-180.0'; this.max='180.0'; return this[varName];")); |
|
480 |
this.a2 = new Array("northBound", "North Boundary must be in the range -90.0 through 90.0.", new Function ("varName", "this.min='-90.0'; this.max='90.0'; return this[varName];")); |
|
481 |
this.a3 = new Array("southBound", "South Boundary must be in the range -90.0 through 90.0.", new Function ("varName", "this.min='-90.0'; this.max='90.0'; return this[varName];")); |
|
482 |
} |
|
483 |
|
|
484 |
/** |
|
485 |
* Check to see if fields are in a valid float range. |
|
486 |
* Fields are not checked if they are disabled. |
|
487 |
* <p> |
|
488 |
* @param form The form validation is taking place on. |
|
489 |
*/ |
|
490 |
function validateFloatRange(form) { |
|
491 |
var isValid = true; |
|
492 |
var focusField = null; |
|
493 |
var i = 0; |
|
494 |
var fields = new Array(); |
|
495 |
var formName = form.getAttributeNode("name"); |
|
496 |
|
|
497 |
oRange = eval('new ' + formName.value + '_floatRange()'); |
|
498 |
for (x in oRange) { |
|
499 |
var field = form[oRange[x][0]]; |
|
500 |
|
|
501 |
if ((field.type == 'hidden' || |
|
502 |
field.type == 'text' || field.type == 'textarea') && |
|
503 |
(field.value.length > 0) && |
|
504 |
field.disabled == false) { |
|
505 |
|
|
506 |
var fMin = parseFloat(oRange[x][2]("min")); |
|
507 |
var fMax = parseFloat(oRange[x][2]("max")); |
|
508 |
var fValue = parseFloat(field.value); |
|
509 |
if (!(fValue >= fMin && fValue <= fMax)) { |
|
510 |
if (i == 0) { |
|
511 |
focusField = field; |
|
512 |
} |
|
513 |
fields[i++] = oRange[x][1]; |
|
514 |
isValid = false; |
|
515 |
} |
|
516 |
} |
|
517 |
} |
|
518 |
if (fields.length > 0) { |
|
519 |
focusField.focus(); |
|
520 |
alert(fields.join('\n')); |
|
521 |
} |
|
522 |
return isValid; |
|
523 |
} |
|
524 |
|
|
525 |
|
|
526 |
/** |
|
527 |
* This is a place holder for common utilities used across the javascript validation |
|
528 |
* |
|
529 |
**/ |
|
530 |
|
|
531 |
|
|
532 |
/** |
|
533 |
* Check to see if fields are a valid byte. |
|
534 |
* Fields are not checked if they are disabled. |
|
535 |
* <p> |
|
536 |
* @param form The form validation is taking place on. |
|
537 |
*/ |
|
538 |
function validateByte(form) { |
|
539 |
var bValid = true; |
|
540 |
var focusField = null; |
|
541 |
var i = 0; |
|
542 |
var fields = new Array(); |
|
543 |
var formName = form.getAttributeNode("name"); |
|
544 |
oByte = eval('new ' + formName.value + '_ByteValidations()'); |
|
545 |
|
|
546 |
for (x in oByte) { |
|
547 |
var field = form[oByte[x][0]]; |
|
548 |
|
|
549 |
if ((field.type == 'hidden' || |
|
550 |
field.type == 'text' || |
|
551 |
field.type == 'textarea' || |
|
552 |
field.type == 'select-one' || |
|
553 |
field.type == 'radio') && |
|
554 |
field.disabled == false) { |
|
555 |
|
|
556 |
var value = ''; |
|
557 |
// get field's value |
|
558 |
if (field.type == "select-one") { |
|
559 |
var si = field.selectedIndex; |
|
560 |
if (si >= 0) { |
|
561 |
value = field.options[si].value; |
|
562 |
} |
|
563 |
} else { |
|
564 |
value = field.value; |
|
565 |
} |
|
566 |
|
|
567 |
if (value.length > 0) { |
|
568 |
if (!isAllDigits(value)) { |
|
569 |
bValid = false; |
|
570 |
if (i == 0) { |
|
571 |
focusField = field; |
|
572 |
} |
|
573 |
fields[i++] = oByte[x][1]; |
|
574 |
|
|
575 |
} else { |
|
576 |
|
|
577 |
var iValue = parseInt(value); |
|
578 |
if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) { |
|
579 |
if (i == 0) { |
|
580 |
focusField = field; |
|
581 |
} |
|
582 |
fields[i++] = oByte[x][1]; |
|
583 |
bValid = false; |
|
584 |
} |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
588 |
} |
|
589 |
} |
|
590 |
if (fields.length > 0) { |
|
591 |
focusField.focus(); |
|
592 |
alert(fields.join('\n')); |
|
593 |
} |
|
594 |
return bValid; |
|
595 |
} |
|
596 |
|
|
597 |
|
|
598 |
/** |
|
599 |
* A field is considered valid if less than the specified maximum. |
|
600 |
* Fields are not checked if they are disabled. |
|
601 |
* <p> |
|
602 |
* <strong>Caution:</strong> Using <code>validateMaxLength</code> on a password field in a |
|
603 |
* login page gives unnecessary information away to hackers. While it only slightly |
|
604 |
* weakens security, we suggest using it only when modifying a password.</p> |
|
605 |
* @param form The form validation is taking place on. |
|
606 |
*/ |
|
607 |
function validateMaxLength(form) { |
|
608 |
var isValid = true; |
|
609 |
var focusField = null; |
|
610 |
var i = 0; |
|
611 |
var fields = new Array(); |
|
612 |
var formName = form.getAttributeNode("name"); |
|
613 |
|
|
614 |
oMaxLength = eval('new ' + formName.value + '_maxlength()'); |
|
615 |
for (x in oMaxLength) { |
|
616 |
var field = form[oMaxLength[x][0]]; |
|
617 |
|
|
618 |
if ((field.type == 'hidden' || |
|
619 |
field.type == 'text' || |
|
620 |
field.type == 'password' || |
|
621 |
field.type == 'textarea') && |
|
622 |
field.disabled == false) { |
|
623 |
|
|
624 |
var iMax = parseInt(oMaxLength[x][2]("maxlength")); |
|
625 |
if (field.value.length > iMax) { |
|
626 |
if (i == 0) { |
|
627 |
focusField = field; |
|
628 |
} |
|
629 |
fields[i++] = oMaxLength[x][1]; |
|
630 |
isValid = false; |
|
631 |
} |
|
632 |
} |
|
633 |
} |
|
634 |
if (fields.length > 0) { |
|
635 |
focusField.focus(); |
|
636 |
alert(fields.join('\n')); |
|
637 |
} |
|
638 |
return isValid; |
|
639 |
} |
|
640 |
|
|
641 |
|
|
642 |
/** |
|
643 |
* Check to see if fields must contain a value. |
|
644 |
* Fields are not checked if they are disabled. |
|
645 |
* <p> |
|
646 |
* @param form The form validation is taking place on. |
|
647 |
*/ |
|
648 |
|
|
649 |
function validateRequired(form) { |
|
650 |
var isValid = true; |
|
651 |
var focusField = null; |
|
652 |
var i = 0; |
|
653 |
var fields = new Array(); |
|
654 |
var formName = form.getAttributeNode("name"); |
|
655 |
|
|
656 |
oRequired = eval('new ' + formName.value + '_required()'); |
|
657 |
|
|
658 |
for (x in oRequired) { |
|
659 |
var field = form[oRequired[x][0]]; |
|
660 |
|
|
661 |
if ((field.type == 'hidden' || |
|
662 |
field.type == 'text' || |
|
663 |
field.type == 'textarea' || |
|
664 |
field.type == 'file' || |
|
665 |
field.type == 'checkbox' || |
|
666 |
field.type == 'select-one' || |
|
667 |
field.type == 'password') && |
|
668 |
field.disabled == false) { |
|
669 |
|
|
670 |
var value = ''; |
|
671 |
// get field's value |
|
672 |
if (field.type == "select-one") { |
|
673 |
var si = field.selectedIndex; |
|
674 |
if (si >= 0) { |
|
675 |
value = field.options[si].value; |
|
676 |
} |
|
677 |
} else if (field.type == 'checkbox') { |
|
678 |
if (field.checked) { |
|
679 |
value = field.value; |
|
680 |
} |
|
681 |
} else { |
|
682 |
value = field.value; |
|
683 |
} |
|
684 |
|
|
685 |
if (trim(value).length == 0) { |
|
686 |
|
|
687 |
if (i == 0) { |
|
688 |
focusField = field; |
|
689 |
} |
|
690 |
fields[i++] = oRequired[x][1]; |
|
691 |
isValid = false; |
|
692 |
} |
|
693 |
} else if (field.type == "select-multiple") { |
|
694 |
var numOptions = field.options.length; |
|
695 |
lastSelected=-1; |
|
696 |
for(loop=numOptions-1;loop>=0;loop--) { |
|
697 |
if(field.options[loop].selected) { |
|
698 |
lastSelected = loop; |
|
699 |
value = field.options[loop].value; |
|
700 |
break; |
|
701 |
} |
|
702 |
} |
|
703 |
if(lastSelected < 0 || trim(value).length == 0) { |
|
704 |
if(i == 0) { |
|
705 |
focusField = field; |
|
706 |
} |
|
707 |
fields[i++] = oRequired[x][1]; |
|
708 |
isValid=false; |
|
709 |
} |
|
710 |
} else if ((field.length > 0) && (field[0].type == 'radio' || field[0].type == 'checkbox')) { |
|
711 |
isChecked=-1; |
|
712 |
for (loop=0;loop < field.length;loop++) { |
|
713 |
if (field[loop].checked) { |
|
714 |
isChecked=loop; |
|
715 |
break; // only one needs to be checked |
|
716 |
} |
|
717 |
} |
|
718 |
if (isChecked < 0) { |
|
719 |
if (i == 0) { |
|
720 |
focusField = field[0]; |
|
721 |
} |
|
722 |
fields[i++] = oRequired[x][1]; |
|
723 |
isValid=false; |
|
724 |
} |
|
725 |
} |
|
726 |
} |
|
727 |
if (fields.length > 0) { |
|
728 |
focusField.focus(); |
|
729 |
alert(fields.join('\n')); |
|
730 |
} |
|
731 |
return isValid; |
|
732 |
} |
|
733 |
|
|
734 |
// Trim whitespace from left and right sides of s. |
|
735 |
function trim(s) { |
|
736 |
return s.replace( /^\s*/, "" ).replace( /\s*$/, "" ); |
|
737 |
} |
|
738 |
|
|
739 |
|
|
740 |
/** |
|
741 |
* Check to see if fields are a valid integer. |
|
742 |
* Fields are not checked if they are disabled. |
|
743 |
* <p> |
|
744 |
* @param form The form validation is taking place on. |
|
745 |
*/ |
|
746 |
function validateInteger(form) { |
|
747 |
var bValid = true; |
|
748 |
var focusField = null; |
|
749 |
var i = 0; |
|
750 |
var fields = new Array(); |
|
751 |
var formName = form.getAttributeNode("name"); |
|
752 |
|
|
753 |
oInteger = eval('new ' + formName.value + '_IntegerValidations()'); |
|
754 |
for (x in oInteger) { |
|
755 |
var field = form[oInteger[x][0]]; |
|
756 |
|
|
757 |
if ((field.type == 'hidden' || |
|
758 |
field.type == 'text' || |
|
759 |
field.type == 'textarea' || |
|
760 |
field.type == 'select-one' || |
|
761 |
field.type == 'radio') && |
|
762 |
field.disabled == false) { |
|
763 |
|
|
764 |
var value = ''; |
|
765 |
// get field's value |
|
766 |
if (field.type == "select-one") { |
|
767 |
var si = field.selectedIndex; |
|
768 |
if (si >= 0) { |
|
769 |
value = field.options[si].value; |
|
770 |
} |
|
771 |
} else { |
|
772 |
value = field.value; |
|
773 |
} |
|
774 |
|
|
775 |
if (value.length > 0) { |
|
776 |
|
|
777 |
if (!isAllDigits(value)) { |
|
778 |
bValid = false; |
|
779 |
if (i == 0) { |
|
780 |
focusField = field; |
|
781 |
} |
|
782 |
fields[i++] = oInteger[x][1]; |
|
783 |
|
|
784 |
} else { |
|
785 |
var iValue = parseInt(value); |
|
786 |
if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) { |
|
787 |
if (i == 0) { |
|
788 |
focusField = field; |
|
789 |
} |
|
790 |
fields[i++] = oInteger[x][1]; |
|
791 |
bValid = false; |
|
792 |
} |
|
793 |
} |
|
794 |
} |
|
795 |
} |
|
796 |
} |
|
797 |
if (fields.length > 0) { |
|
798 |
focusField.focus(); |
|
799 |
alert(fields.join('\n')); |
|
800 |
} |
|
801 |
return bValid; |
|
802 |
} |
|
803 |
|
|
804 |
function isAllDigits(argvalue) { |
|
805 |
argvalue = argvalue.toString(); |
|
806 |
var validChars = "0123456789"; |
|
807 |
var startFrom = 0; |
|
808 |
if (argvalue.substring(0, 2) == "0x") { |
|
809 |
validChars = "0123456789abcdefABCDEF"; |
|
810 |
startFrom = 2; |
|
811 |
} else if (argvalue.charAt(0) == "0") { |
|
812 |
validChars = "01234567"; |
|
813 |
startFrom = 1; |
|
814 |
} else if (argvalue.charAt(0) == "-") { |
|
815 |
startFrom = 1; |
|
816 |
} |
|
817 |
|
|
818 |
for (var n = startFrom; n < argvalue.length; n++) { |
|
819 |
if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false; |
|
820 |
} |
|
821 |
return true; |
|
822 |
} |
|
823 |
|
|
824 |
|
|
825 |
/** |
|
826 |
* Check to see if fields are a valid date. |
|
827 |
* Fields are not checked if they are disabled. |
|
828 |
* <p> |
|
829 |
* @param form The form validation is taking place on. |
|
830 |
*/ |
|
831 |
function validateDate(form) { |
|
832 |
var bValid = true; |
|
833 |
var focusField = null; |
|
834 |
var i = 0; |
|
835 |
var fields = new Array(); |
|
836 |
var formName = form.getAttributeNode("name"); |
|
837 |
|
|
838 |
oDate = eval('new ' + formName.value + '_DateValidations()'); |
|
839 |
|
|
840 |
for (x in oDate) { |
|
841 |
var field = form[oDate[x][0]]; |
|
842 |
var value = field.value; |
|
843 |
var datePattern = oDate[x][2]("datePatternStrict"); |
|
844 |
// try loose pattern |
|
845 |
if (datePattern == null) |
|
846 |
datePattern = oDate[x][2]("datePattern"); |
|
847 |
if ((field.type == 'hidden' || |
|
848 |
field.type == 'text' || |
|
849 |
field.type == 'textarea') && |
|
850 |
(value.length > 0) && (datePattern.length > 0) && |
|
851 |
field.disabled == false) { |
|
852 |
var MONTH = "MM"; |
|
853 |
var DAY = "dd"; |
|
854 |
var YEAR = "yyyy"; |
|
855 |
var orderMonth = datePattern.indexOf(MONTH); |
|
856 |
var orderDay = datePattern.indexOf(DAY); |
|
857 |
var orderYear = datePattern.indexOf(YEAR); |
|
858 |
if ((orderDay < orderYear && orderDay > orderMonth)) { |
|
859 |
var iDelim1 = orderMonth + MONTH.length; |
|
860 |
var iDelim2 = orderDay + DAY.length; |
|
861 |
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); |
|
862 |
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); |
|
863 |
if (iDelim1 == orderDay && iDelim2 == orderYear) { |
|
864 |
dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); |
|
865 |
} else if (iDelim1 == orderDay) { |
|
866 |
dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); |
|
867 |
} else if (iDelim2 == orderYear) { |
|
868 |
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$"); |
|
869 |
} else { |
|
870 |
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$"); |
|
871 |
} |
|
872 |
var matched = dateRegexp.exec(value); |
|
873 |
if(matched != null) { |
|
874 |
if (!isValidDate(matched[2], matched[1], matched[3])) { |
|
875 |
if (i == 0) { |
|
876 |
focusField = field; |
|
877 |
} |
|
878 |
fields[i++] = oDate[x][1]; |
|
879 |
bValid = false; |
|
880 |
} |
|
881 |
} else { |
|
882 |
if (i == 0) { |
|
883 |
focusField = field; |
|
884 |
} |
|
885 |
fields[i++] = oDate[x][1]; |
|
886 |
bValid = false; |
|
887 |
} |
|
888 |
} else if ((orderMonth < orderYear && orderMonth > orderDay)) { |
|
889 |
var iDelim1 = orderDay + DAY.length; |
|
890 |
var iDelim2 = orderMonth + MONTH.length; |
|
891 |
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); |
|
892 |
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); |
|
893 |
if (iDelim1 == orderMonth && iDelim2 == orderYear) { |
|
894 |
dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); |
|
895 |
} else if (iDelim1 == orderMonth) { |
|
896 |
dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); |
|
897 |
} else if (iDelim2 == orderYear) { |
|
898 |
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$"); |
|
899 |
} else { |
|
900 |
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$"); |
|
901 |
} |
|
902 |
var matched = dateRegexp.exec(value); |
|
903 |
if(matched != null) { |
|
904 |
if (!isValidDate(matched[1], matched[2], matched[3])) { |
|
905 |
if (i == 0) { |
|
906 |
focusField = field; |
|
907 |
} |
|
908 |
fields[i++] = oDate[x][1]; |
|
909 |
bValid = false; |
|
910 |
} |
|
911 |
} else { |
|
912 |
if (i == 0) { |
|
913 |
focusField = field; |
|
914 |
} |
|
915 |
fields[i++] = oDate[x][1]; |
|
916 |
bValid = false; |
|
917 |
} |
|
918 |
} else if ((orderMonth > orderYear && orderMonth < orderDay)) { |
|
919 |
var iDelim1 = orderYear + YEAR.length; |
|
920 |
var iDelim2 = orderMonth + MONTH.length; |
|
921 |
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); |
|
922 |
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); |
|
923 |
if (iDelim1 == orderMonth && iDelim2 == orderDay) { |
|
924 |
dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); |
|
925 |
} else if (iDelim1 == orderMonth) { |
|
926 |
dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$"); |
|
927 |
} else if (iDelim2 == orderDay) { |
|
928 |
dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$"); |
|
929 |
} else { |
|
930 |
dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$"); |
|
931 |
} |
|
932 |
var matched = dateRegexp.exec(value); |
|
933 |
if(matched != null) { |
|
934 |
if (!isValidDate(matched[3], matched[2], matched[1])) { |
|
935 |
if (i == 0) { |
|
936 |
focusField = field; |
|
937 |
} |
|
938 |
fields[i++] = oDate[x][1]; |
|
939 |
bValid = false; |
|
940 |
} |
|
941 |
} else { |
|
942 |
if (i == 0) { |
|
943 |
focusField = field; |
|
944 |
} |
|
945 |
fields[i++] = oDate[x][1]; |
|
946 |
bValid = false; |
|
947 |
} |
|
948 |
} else { |
|
949 |
if (i == 0) { |
|
950 |
focusField = field; |
|
951 |
} |
|
952 |
fields[i++] = oDate[x][1]; |
|
953 |
bValid = false; |
|
954 |
} |
|
955 |
} |
|
956 |
} |
|
957 |
if (fields.length > 0) { |
|
958 |
focusField.focus(); |
|
959 |
alert(fields.join('\n')); |
|
960 |
} |
|
961 |
return bValid; |
|
962 |
} |
|
963 |
|
|
964 |
function isValidDate(day, month, year) { |
|
965 |
if (month < 1 || month > 12) { |
|
966 |
return false; |
|
967 |
} |
|
968 |
if (day < 1 || day > 31) { |
|
969 |
return false; |
|
970 |
} |
|
971 |
if ((month == 4 || month == 6 || month == 9 || month == 11) && |
|
972 |
(day == 31)) { |
|
973 |
return false; |
|
974 |
} |
|
975 |
if (month == 2) { |
|
976 |
var leap = (year % 4 == 0 && |
|
977 |
(year % 100 != 0 || year % 400 == 0)); |
|
978 |
if (day>29 || (day == 29 && !leap)) { |
|
979 |
return false; |
|
980 |
} |
|
981 |
} |
|
982 |
return true; |
|
983 |
} |
|
984 |
|
|
985 |
|
|
986 |
/** |
|
987 |
* Check to see if fields are a valid creditcard number based on Luhn checksum. |
|
988 |
* Fields are not checked if they are disabled. |
|
989 |
* <p> |
|
990 |
* @param form The form validation is taking place on. |
|
991 |
*/ |
|
992 |
function validateCreditCard(form) { |
|
993 |
var bValid = true; |
|
994 |
var focusField = null; |
|
995 |
var i = 0; |
|
996 |
var fields = new Array(); |
|
997 |
var formName = form.getAttributeNode("name"); |
|
998 |
|
|
999 |
oCreditCard = eval('new ' + formName.value + '_creditCard()'); |
|
1000 |
|
|
1001 |
for (x in oCreditCard) { |
|
1002 |
if ((form[oCreditCard[x][0]].type == 'text' || |
|
1003 |
form[oCreditCard[x][0]].type == 'textarea') && |
|
1004 |
(form[oCreditCard[x][0]].value.length > 0) && |
|
1005 |
form[oCreditCard[x][0]].disabled == false) { |
|
1006 |
if (!luhnCheck(form[oCreditCard[x][0]].value)) { |
|
1007 |
if (i == 0) { |
|
1008 |
focusField = form[oCreditCard[x][0]]; |
|
1009 |
} |
|
1010 |
fields[i++] = oCreditCard[x][1]; |
|
1011 |
bValid = false; |
|
1012 |
} |
|
1013 |
} |
|
1014 |
} |
|
1015 |
if (fields.length > 0) { |
|
1016 |
focusField.focus(); |
|
1017 |
alert(fields.join('\n')); |
|
1018 |
} |
|
1019 |
return bValid; |
|
1020 |
} |
|
1021 |
|
|
1022 |
/** |
|
1023 |
* Checks whether a given credit card number has a valid Luhn checksum. |
|
1024 |
* This allows you to spot most randomly made-up or garbled credit card numbers immediately. |
|
1025 |
* Reference: http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html |
|
1026 |
*/ |
|
1027 |
function luhnCheck(cardNumber) { |
|
1028 |
if (isLuhnNum(cardNumber)) { |
|
1029 |
var no_digit = cardNumber.length; |
|
1030 |
var oddoeven = no_digit & 1; |
|
1031 |
var sum = 0; |
|
1032 |
for (var count = 0; count < no_digit; count++) { |
|
1033 |
var digit = parseInt(cardNumber.charAt(count)); |
|
1034 |
if (!((count & 1) ^ oddoeven)) { |
|
1035 |
digit *= 2; |
|
1036 |
if (digit > 9) digit -= 9; |
|
1037 |
}; |
|
1038 |
sum += digit; |
|
1039 |
}; |
|
1040 |
if (sum == 0) return false; |
|
1041 |
if (sum % 10 == 0) return true; |
|
1042 |
}; |
|
1043 |
return false; |
|
1044 |
} |
|
1045 |
|
|
1046 |
function isLuhnNum(argvalue) { |
|
1047 |
argvalue = argvalue.toString(); |
|
1048 |
if (argvalue.length == 0) { |
|
1049 |
return false; |
|
1050 |
} |
|
1051 |
for (var n = 0; n < argvalue.length; n++) { |
|
1052 |
if ((argvalue.substring(n, n+1) < "0") || |
|
1053 |
(argvalue.substring(n,n+1) > "9")) { |
|
1054 |
return false; |
|
1055 |
} |
|
1056 |
} |
|
1057 |
return true; |
|
1058 |
} |
|
1059 |
|
|
1060 |
|
|
1061 |
/** |
|
1062 |
* Check to see if fields is in a valid integer range. |
|
1063 |
* Fields are not checked if they are disabled. |
|
1064 |
* <p> |
|
1065 |
* @param form The form validation is taking place on. |
|
1066 |
*/ |
|
1067 |
function validateIntRange(form) { |
|
1068 |
var isValid = true; |
|
1069 |
var focusField = null; |
|
1070 |
var i = 0; |
|
1071 |
var fields = new Array(); |
|
1072 |
var formName = form.getAttributeNode("name"); |
|
1073 |
|
|
1074 |
oRange = eval('new ' + formName.value + '_intRange()'); |
|
1075 |
for (x in oRange) { |
|
1076 |
var field = form[oRange[x][0]]; |
|
1077 |
if (field.disabled == false) { |
|
1078 |
var value = ''; |
|
1079 |
if (field.type == 'hidden' || |
|
1080 |
field.type == 'text' || field.type == 'textarea' || |
|
1081 |
field.type == 'radio' ) { |
|
1082 |
value = field.value; |
|
1083 |
} |
|
1084 |
if (field.type == 'select-one') { |
|
1085 |
var si = field.selectedIndex; |
|
1086 |
if (si >= 0) { |
|
1087 |
value = field.options[si].value; |
|
1088 |
} |
|
1089 |
} |
|
1090 |
if (value.length > 0) { |
|
1091 |
var iMin = parseInt(oRange[x][2]("min")); |
|
1092 |
var iMax = parseInt(oRange[x][2]("max")); |
|
1093 |
var iValue = parseInt(value); |
|
1094 |
if (!(iValue >= iMin && iValue <= iMax)) { |
|
1095 |
if (i == 0) { |
|
1096 |
focusField = field; |
|
1097 |
} |
|
1098 |
fields[i++] = oRange[x][1]; |
|
1099 |
isValid = false; |
|
1100 |
} |
|
1101 |
} |
|
1102 |
} |
|
1103 |
} |
|
1104 |
if (fields.length > 0) { |
|
1105 |
focusField.focus(); |
|
1106 |
alert(fields.join('\n')); |
|
1107 |
} |
|
1108 |
return isValid; |
|
1109 |
} |
|
1110 |
|
|
1111 |
|
|
1112 |
/** |
|
1113 |
* Check to see if fields are a valid short. |
|
1114 |
* Fields are not checked if they are disabled. |
|
1115 |
* <p> |
|
1116 |
* @param form The form validation is taking place on. |
|
1117 |
*/ |
|
1118 |
function validateShort(form) { |
|
1119 |
var bValid = true; |
|
1120 |
var focusField = null; |
|
1121 |
var i = 0; |
|
1122 |
var fields = new Array(); |
|
1123 |
var formName = form.getAttributeNode("name"); |
|
1124 |
|
|
1125 |
oShort = eval('new ' + formName.value + '_ShortValidations()'); |
|
1126 |
|
|
1127 |
for (x in oShort) { |
|
1128 |
var field = form[oShort[x][0]]; |
|
1129 |
|
|
1130 |
if ((field.type == 'hidden' || |
|
1131 |
field.type == 'text' || |
|
1132 |
field.type == 'textarea' || |
|
1133 |
field.type == 'select-one' || |
|
1134 |
field.type == 'radio') && |
|
1135 |
field.disabled == false) { |
|
1136 |
|
|
1137 |
var value = ''; |
|
1138 |
// get field's value |
|
1139 |
if (field.type == "select-one") { |
|
1140 |
var si = field.selectedIndex; |
|
1141 |
if (si >= 0) { |
|
1142 |
value = field.options[si].value; |
|
1143 |
} |
|
1144 |
} else { |
|
1145 |
value = field.value; |
|
1146 |
} |
|
1147 |
|
|
1148 |
if (value.length > 0) { |
|
1149 |
if (!isAllDigits(value)) { |
|
1150 |
bValid = false; |
|
1151 |
if (i == 0) { |
|
1152 |
focusField = field; |
|
1153 |
} |
|
1154 |
fields[i++] = oShort[x][1]; |
|
1155 |
|
|
1156 |
} else { |
|
1157 |
|
|
1158 |
var iValue = parseInt(value); |
|
1159 |
if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) { |
|
1160 |
if (i == 0) { |
|
1161 |
focusField = field; |
|
1162 |
} |
|
1163 |
fields[i++] = oShort[x][1]; |
|
1164 |
bValid = false; |
|
1165 |
} |
|
1166 |
} |
|
1167 |
} |
|
1168 |
} |
|
1169 |
} |
|
1170 |
if (fields.length > 0) { |
|
1171 |
focusField.focus(); |
|
1172 |
alert(fields.join('\n')); |
|
1173 |
} |
|
1174 |
return bValid; |
|
1175 |
} |
|
1176 |
|
|
1177 |
|
|
1178 |
/** |
|
1179 |
* Check to see if fields are a valid float. |
|
1180 |
* Fields are not checked if they are disabled. |
|
1181 |
* <p> |
|
1182 |
* @param form The form validation is taking place on. |
|
1183 |
*/ |
|
1184 |
function validateFloat(form) { |
|
1185 |
var bValid = true; |
|
1186 |
var focusField = null; |
|
1187 |
var i = 0; |
|
1188 |
var fields = new Array(); |
|
1189 |
var formName = form.getAttributeNode("name"); |
|
1190 |
|
|
1191 |
oFloat = eval('new ' + formName.value + '_FloatValidations()'); |
|
1192 |
for (x in oFloat) { |
|
1193 |
var field = form[oFloat[x][0]]; |
|
1194 |
|
|
1195 |
if ((field.type == 'hidden' || |
|
1196 |
field.type == 'text' || |
|
1197 |
field.type == 'textarea' || |
|
1198 |
field.type == 'select-one' || |
|
1199 |
field.type == 'radio') && |
|
1200 |
field.disabled == false) { |
|
1201 |
|
|
1202 |
var value = ''; |
|
1203 |
// get field's value |
|
1204 |
if (field.type == "select-one") { |
|
1205 |
var si = field.selectedIndex; |
|
1206 |
if (si >= 0) { |
|
1207 |
value = field.options[si].value; |
|
1208 |
} |
|
1209 |
} else { |
|
1210 |
value = field.value; |
|
1211 |
} |
|
1212 |
|
|
1213 |
if (value.length > 0) { |
|
1214 |
// remove '.' before checking digits |
|
1215 |
var tempArray = value.split('.'); |
|
1216 |
//Strip off leading '0' |
|
1217 |
var zeroIndex = 0; |
|
1218 |
var joinedString= tempArray.join(''); |
|
1219 |
while (joinedString.charAt(zeroIndex) == '0') { |
|
1220 |
zeroIndex++; |
|
1221 |
} |
|
1222 |
var noZeroString = joinedString.substring(zeroIndex,joinedString.length); |
|
1223 |
|
|
1224 |
if (!isAllDigits(noZeroString)) { |
|
1225 |
bValid = false; |
|
1226 |
if (i == 0) { |
|
1227 |
focusField = field; |
|
1228 |
} |
|
1229 |
fields[i++] = oFloat[x][1]; |
|
1230 |
|
|
1231 |
} else { |
|
1232 |
var iValue = parseFloat(value); |
|
1233 |
if (isNaN(iValue)) { |
|
1234 |
if (i == 0) { |
|
1235 |
focusField = field; |
|
1236 |
} |
|
1237 |
fields[i++] = oFloat[x][1]; |
|
1238 |
bValid = false; |
|
1239 |
} |
|
1240 |
} |
|
1241 |
} |
|
1242 |
} |
|
1243 |
} |
|
1244 |
if (fields.length > 0) { |
|
1245 |
focusField.focus(); |
|
1246 |
alert(fields.join('\n')); |
|
1247 |
} |
|
1248 |
return bValid; |
|
1249 |
} |
|
1250 |
|
|
1251 |
|
|
1252 |
/** |
|
1253 |
* Check to see if fields are a valid email address. |
|
1254 |
* Fields are not checked if they are disabled. |
|
1255 |
* <p> |
|
1256 |
* @param form The form validation is taking place on. |
|
1257 |
*/ |
|
1258 |
function validateEmail(form) { |
|
1259 |
var bValid = true; |
|
1260 |
var focusField = null; |
|
1261 |
var i = 0; |
|
1262 |
var fields = new Array(); |
|
1263 |
var formName = form.getAttributeNode("name"); |
|
1264 |
|
|
1265 |
|
|
1266 |
oEmail = eval('new ' + formName.value + '_email()'); |
|
1267 |
|
|
1268 |
for (x in oEmail) { |
|
1269 |
var field = form[oEmail[x][0]]; |
|
1270 |
if ((field.type == 'hidden' || |
|
1271 |
field.type == 'text' || |
|
1272 |
field.type == 'textarea') && |
|
1273 |
(field.value.length > 0) && |
|
1274 |
field.disabled == false) { |
|
1275 |
if (!checkEmail(field.value)) { |
|
1276 |
if (i == 0) { |
|
1277 |
focusField = field; |
|
1278 |
} |
|
1279 |
fields[i++] = oEmail[x][1]; |
|
1280 |
bValid = false; |
|
1281 |
} |
|
1282 |
} |
|
1283 |
} |
|
1284 |
if (fields.length > 0) { |
|
1285 |
focusField.focus(); |
|
1286 |
alert(fields.join('\n')); |
|
1287 |
} |
|
1288 |
return bValid; |
|
1289 |
} |
|
1290 |
|
|
1291 |
/** |
|
1292 |
* Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com), |
|
1293 |
* http://javascript.internet.com |
|
1294 |
*/ |
|
1295 |
function checkEmail(emailStr) { |
|
1296 |
if (emailStr.length == 0) { |
|
1297 |
return true; |
|
1298 |
} |
|
1299 |
var emailPat=/^(.+)@(.+)$/; |
|
1300 |
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; |
|
1301 |
var validChars="\[^\\s" + specialChars + "\]"; |
|
1302 |
var quotedUser="(\"[^\"]*\")"; |
|
1303 |
var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/; |
|
1304 |
var atom=validChars + '+'; |
|
1305 |
var word="(" + atom + "|" + quotedUser + ")"; |
|
1306 |
var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); |
|
1307 |
var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$"); |
|
1308 |
var matchArray=emailStr.match(emailPat); |
|
1309 |
if (matchArray == null) { |
|
1310 |
return false; |
|
1311 |
} |
|
1312 |
var user=matchArray[1]; |
|
1313 |
var domain=matchArray[2]; |
|
1314 |
if (user.match(userPat) == null) { |
|
1315 |
return false; |
|
1316 |
} |
|
1317 |
var IPArray = domain.match(ipDomainPat); |
|
1318 |
if (IPArray != null) { |
|
1319 |
for (var i = 1; i <= 4; i++) { |
|
1320 |
if (IPArray[i] > 255) { |
|
1321 |
return false; |
|
1322 |
} |
|
1323 |
} |
|
1324 |
return true; |
|
1325 |
} |
|
1326 |
var domainArray=domain.match(domainPat); |
|
1327 |
if (domainArray == null) { |
|
1328 |
return false; |
|
1329 |
} |
|
1330 |
var atomPat=new RegExp(atom,"g"); |
|
1331 |
var domArr=domain.match(atomPat); |
|
1332 |
var len=domArr.length; |
|
1333 |
if ((domArr[domArr.length-1].length < 2) || |
|
1334 |
(domArr[domArr.length-1].length > 3)) { |
|
1335 |
return false; |
|
1336 |
} |
|
1337 |
if (len < 2) { |
|
1338 |
return false; |
|
1339 |
} |
|
1340 |
return true; |
|
1341 |
} |
|
1342 |
|
|
1343 |
|
|
1344 |
/** |
|
1345 |
* Check to see if fields are a valid using a regular expression. |
|
1346 |
* Fields are not checked if they are disabled. |
|
1347 |
* <p> |
|
1348 |
* @param form The form validation is taking place on. |
|
1349 |
*/ |
|
1350 |
function validateMask(form) { |
|
1351 |
var isValid = true; |
|
1352 |
var focusField = null; |
|
1353 |
var i = 0; |
|
1354 |
var fields = new Array(); |
|
1355 |
var formName = form.getAttributeNode("name"); |
|
1356 |
|
|
1357 |
oMasked = eval('new ' + formName.value + '_mask()'); |
|
1358 |
for (x in oMasked) { |
|
1359 |
var field = form[oMasked[x][0]]; |
|
1360 |
|
|
1361 |
if ((field.type == 'hidden' || |
|
1362 |
field.type == 'text' || |
|
1363 |
field.type == 'textarea' || |
|
1364 |
field.type == 'file') && |
|
1365 |
(field.value.length > 0) && |
|
1366 |
field.disabled == false) { |
|
1367 |
|
|
1368 |
if (!matchPattern(field.value, oMasked[x][2]("mask"))) { |
|
1369 |
if (i == 0) { |
|
1370 |
focusField = field; |
|
1371 |
} |
|
1372 |
fields[i++] = oMasked[x][1]; |
|
1373 |
isValid = false; |
|
1374 |
} |
|
1375 |
} |
|
1376 |
} |
|
1377 |
|
|
1378 |
if (fields.length > 0) { |
|
1379 |
focusField.focus(); |
|
1380 |
alert(fields.join('\n')); |
|
1381 |
} |
|
1382 |
return isValid; |
|
1383 |
} |
|
1384 |
|
|
1385 |
function matchPattern(value, mask) { |
|
1386 |
return mask.exec(value); |
|
1387 |
} |
|
1388 |
|
|
1389 |
|
|
1390 |
/** |
|
1391 |
* A field is considered valid if greater than the specified minimum. |
|
1392 |
* Fields are not checked if they are disabled. |
|
1393 |
* <p> |
|
1394 |
* <strong>Caution:</strong> Using <code>validateMinLength</code> on a password field in a |
|
1395 |
* login page gives unnecessary information away to hackers. While it only slightly |
|
1396 |
* weakens security, we suggest using it only when modifying a password.</p> |
|
1397 |
* @param form The form validation is taking place on. |
|
1398 |
*/ |
|
1399 |
function validateMinLength(form) { |
|
1400 |
var isValid = true; |
|
1401 |
var focusField = null; |
|
1402 |
var i = 0; |
|
1403 |
var fields = new Array(); |
|
1404 |
var formName = form.getAttributeNode("name"); |
|
1405 |
|
|
1406 |
|
|
1407 |
oMinLength = eval('new ' + formName.value + '_minlength()'); |
|
1408 |
|
|
1409 |
for (x in oMinLength) { |
|
1410 |
var field = form[oMinLength[x][0]]; |
|
1411 |
|
|
1412 |
if ((field.type == 'hidden' || |
|
1413 |
field.type == 'text' || |
|
1414 |
field.type == 'password' || |
|
1415 |
field.type == 'textarea') && |
|
1416 |
field.disabled == false) { |
|
1417 |
|
|
1418 |
var iMin = parseInt(oMinLength[x][2]("minlength")); |
|
1419 |
if ((trim(field.value).length > 0) && (field.value.length < iMin)) { |
|
1420 |
if (i == 0) { |
|
1421 |
focusField = field; |
|
1422 |
} |
|
1423 |
fields[i++] = oMinLength[x][1]; |
|
1424 |
isValid = false; |
|
1425 |
} |
|
1426 |
} |
|
1427 |
} |
|
1428 |
if (fields.length > 0) { |
|
1429 |
focusField.focus(); |
|
1430 |
alert(fields.join('\n')); |
|
1431 |
} |
|
1432 |
return isValid; |
|
1433 |
} |
|
1434 |
|
|
1435 |
//End JavaScript input validation checking code. --> |
|
1436 |
</script> |
|
445 | 1437 |
</td> |
446 | 1438 |
</tr> |
447 | 1439 |
<tr> |
Also available in: Unified diff
Bug #2207. Metacat Advanced Search interface.
Improvements to Advanced Search form:
(1) Delete keywordSearch() function. Not used in advanced search form.
(2) Re-initialize hidden form values for geographic boundaries.
(3) Change table width to 100% so horizontal rules will span the full width.
(4) Comment out input field that allows user to restrict search to a particular LTER site. This is only useful within LTER.
(5) Add client-side input validation code. Not all of this JavaScript is really needed; some can eventually be removed.