Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5def52b0

Von Thomas Kasulke vor mehr als 17 Jahren hinzugefügt

  • ID 5def52b0f6322414eb2a8f554b85e1320d230b2c
  • Vorgänger b75911aa
  • Nachfolger 05fea791

Erweiterung der common.js um die function setupDateFormat(dateFormat, wrongDateFormat) und check_right_date_format(input_name), welche ein Datum auf Richtigkeit
überprüfen. Einzubingen wie folgt:

- in jeder pl, in der input-tags überprüft werden sollen, muss $onload durch folgendes erweitert werden:
$onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
- die common.js muss eingebunden sein
- in zu überprüfendem input-tag muß folgendes stehen:
onBlur=\"check_right_date_format(this)\"

Die Funktion check_right_date_format, welche vorher vorhanden war, wurde in check_right_number_format(input_name) umbenannt!!!

Unterschiede anzeigen:

js/common.js
7 7
  else {
8 8
    thpoint = null;
9 9
  }
10
  wrongformat = wrongFormat;  
10
  wrongNumberformat = wrongFormat + " ( " + numberformat + " ) ";  
11
}
12

  
13
function setupDateFormat(setDateFormat, setWrongDateFormat) {
14
  dateFormat = setDateFormat;
15
  wrongDateFormat = setWrongDateFormat + " ( " + setDateFormat + " ) ";
16
  formatArray = new Array();
17
  if(dateFormat.match(/^\w\w\W/)) {
18
    seperator = dateFormat.substring(2,3);
19
  }
20
  else {
21
    seperator = dateFormat.substring(4,5);
22
  }
11 23
}
12 24

  
13 25
function centerParms(width,height,extra) {
......
35 47
  window.open(url, "_new_generic", parm);
36 48
  }
37 49

  
38
  function check_right_date_format(input_name) {
39
    var decnumbers = input_name.value.split(decpoint);
40
    if(thpoint) {
41
      var thnumbers = input_name.value.split(thpoint);
42
      if(thnumbers[thnumbers.length-1].match(/.+decpoint$/g)) {
43
        thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-1);
44
      }
45
      if(thnumbers[thnumbers.length-1].match(/.+decpoint\d$/g)) {
46
        thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-2);
47
      }  
48
      if(thnumbers[thnumbers.length-1].match(/.+decpoint\d\d$/g)) {
49
        thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-3);
50
      }  
51
      for(var i = 1; i < thnumbers.length; i++) {
52
        if(!thnumbers[i].match(/\d\d\d/g)) {
53
          return show_alert_and_focus(input_name);
54
        }
55
        if(thnumbers[i].match(/.*decpoint.*|.*thpoint.*/g)) {
56
          return show_alert_and_focus(input_name);
57
        }
50
function check_right_number_format(input_name) {
51
  var decnumbers = input_name.value.split(decpoint);
52
  if(thpoint) {
53
    var thnumbers = input_name.value.split(thpoint);
54
    if(thnumbers[thnumbers.length-1].match(/.+decpoint$/g)) {
55
      thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-1);
56
    }
57
    if(thnumbers[thnumbers.length-1].match(/.+decpoint\d$/g)) {
58
      thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-2);
59
    }  
60
    if(thnumbers[thnumbers.length-1].match(/.+decpoint\d\d$/g)) {
61
      thnumbers[thnumbers.length-1] = thnumbers[thnumbers.length-1].substring(thnumbers[thnumbers.length-1].length-3);
62
    }  
63
    for(var i = 1; i < thnumbers.length; i++) {
64
      if(!thnumbers[i].match(/\d\d\d/g)) {
65
        return show_alert_and_focus(input_name, wrongNumberFormat);
58 66
      }
59
      if(decnumbers.length > 2 || (decnumbers.length > 1 ? (decnumbers[1].length > 2) : false)) {
60
        return show_alert_and_focus(input_name);
67
      if(thnumbers[i].match(/.*decpoint.*|.*thpoint.*/g)) {
68
        return show_alert_and_focus(input_name, wrongNumberFormat);
61 69
      }
62 70
    }
63
    else {
64
      if(decnumbers.length > 1 || decnumbers[0].length > 2) {
65
        return show_alert_and_focus(input_name);
66
      }
71
    if(decnumbers.length > 2 || (decnumbers.length > 1 ? (decnumbers[1].length > 2) : false)) {
72
      return show_alert_and_focus(input_name, wrongNumberFormat);
67 73
    }
68 74
  }
69
  
70
  function show_alert_and_focus(input_name) {
71
    input_name.select();
72
    alert(wrongformat + "\n\r\n\r--> " + input_name.value);
73
    input_name.focus();
74
    return false;
75
  else {
76
    if(decnumbers.length > 1 || decnumbers[0].length > 2) {
77
      return show_alert_and_focus(input_name, wrongNumberFormat);
78
    }
79
  }
80
}
81

  
82
function check_right_date_format(input_name) {
83
  var matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + "\$","ig");
84
  if(!(dateFormat.lastIndexOf("y") == 3) && !matching.test(input_name.value)) {
85
    matching = new RegExp(dateFormat.replace(/\w/g, '\\d') + '\\d\\d\$', "ig");
86
    if(!matching.test(input_name.value)) {
87
      return show_alert_and_focus(input_name, wrongDateFormat);
88
    }
75 89
  }
90
  else {
91
    if (dateFormat.lastIndexOf("y") == 3 && !matching.test(input_name.value)) { 
92
      return show_alert_and_focus(input_name, wrongDateFormat);
93
    }
94
  }
95
}
96

  
97
function validate_dates(input_name_1, input_name_2) {
98
  var tempArray1 = new Array();
99
  var tempArray2 = new Array();
100
  tempArray1 = getDateArray(input_name_1);
101
  tempArray2 = getDateArray(input_name_2);
102
  if(check_right_date_format(input_name_1) && check_right_date_format(input_name_2)) {
103
    if(!((new Date(tempArray2[0], tempArray2[1], tempArray2[2])).getTime() >= (new Date(tempArray1[0], tempArray1[1], tempArray1[2])).getTime())) {
104
      show_alert_and_focus(input_name_1, wrongDateFormat);
105
      return show_alert_and_focus(input_name_2, wrongDateFormat);
106
    }
107
    if(!((new Date(tempArray2[0], tempArray2[1], tempArray2[2])).getTime() >= (new Date(1900, 1, 1)).getTime())) {
108
      show_alert_and_focus(input_name_1, wrongDateFormat);
109
      return show_alert_and_focus(input_name_2, wrongDateFormat);
110
    }
111
  }
112
}
113

  
114
function getDateArray(input_name) {
115
  formatArray[2] = input_name.value.substring(dateFormat.indexOf("d"), 2);
116
  formatArray[1] = input_name.value.substring(dateFormat.indexOf("m"), 2);
117
  formatArray[0] = input_name.value.substring(dateFormat.indexOf("y"), (dateFormat.length == 10 ? 4 : 2));
118
  if(dateFormat.length == 8) {
119
    formatArray[0] += (formatArray[0] < 70 ? 2000 : 1900);
120
  }
121
  return formatArray;
122
}
123

  
124
function show_alert_and_focus(input_name, errorMessage) {
125
  input_name.select();
126
  alert(errorMessage + "\n\r\n\r--> " + input_name.value);
127
  input_name.focus();
128
  return false;
129
}
76 130
  

Auch abrufbar als: Unified diff