title: Unable to get property '1' of undefined or null reference
body: <p>I have a calendar on my site that opens a pop-up box showing a RGB color selector. It works fine in all browsers apart from IE8. My code is below.</p>
  
  <pre><code>function rgb2hex(rgb) {
      rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
      function hex(x) {
          return ("0" + parseInt(x).toString(16)).slice(-2);
      }
      return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
  }
  </code></pre>
  
  <p>This is the error</p>
  
  <blockquote>
    <p>SCRIPT5007: Unable to get property '1' of undefined or null reference</p>
  </blockquote>
  
  <p>Which points to this line </p>
  
  <pre><code>return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
  </code></pre>
  
  <p>I am not familiar with this code as it was completed by someone else at my workplace who has went on holiday for a couple of weeks. If anyone can help point me in the right direction it would be greatly appreciated.</p>
  
  <p>EDIT</p>
  
  <p>This is where the function is called. When I console.log(bgColor) in IE8 it shows up as #rgb(238, 238, 238), so i don't see why it isn't working. Maybe it is me being stupid but for life of me I cannot see it.</p>
  
  <pre><code>$('.period_day').click(function(e) {
      var bgColor = $(this).css('background-color');
  
  if (rgb2hex(bgColor) == "#eeeeee") {
      $('.colour_picker').css('background-color', '#ff0000');
      $('#cal_colour_val').val('#ff0000');
  } else {
      $('.colour_picker').css('background-color', bgColor);
      $('#cal_colour_val').val(bgColor);
  }
  });
  </code></pre>