user1209235
user1209235

Reputation: 17

'1' is null or no object ... again

I have this piece of JS that throws the mentioned error (IE8 & 7). I have looked a thousand times for a trailing comma and cannot find it - may be the problem is elsewhere? Any help would be appreciated.

ts.addParser({
id: 'customDate',
is: function(s) {
  return false;
},
format: function(s) {
  var date = s.match(/^\s(\w{1,2})[.](\d{1,2})[.](\d{4})[,]\s(\d{1,2})[:](\d{1,2})\s\bUhr\b\s$/);

  var day = String(date[1]);
  var month = String(date[2]);
  var year = String(date[3]);
  var hour = String(date[4]);
  var minute = String(date[5]);
  return '' + year + month + day + hour + minute;
},  type: 'numeric'   
});

Upvotes: 0

Views: 72

Answers (1)

Halcyon
Halcyon

Reputation: 57721

If the regex match fails date will be null. So

var day = String(date[1]);

will fail.

Add a check:

if (date === null) // return error or some default

Upvotes: 3

Related Questions