title: Validating css color names
body: <p>I've written a jQuery plugin that accepts css colors for some of its parameters.</p>
  
  <p>I want to validate them. If it was just a hex or rgb value I could do that with a regular expression, but how do I validate all 147 valid color names without bloating the plugin?</p>
  
  <p>I was wondering if there is some way of attempting to apply a style (maybe with jquery) and then catching an error from the browser if it is not valid?</p>
  
  <p>Edit: powtac and Pantelis came up with a solution, but they both missed edge cases, so I am including a full solution here: </p>
  
  <pre><code>var validateCssColour = function(colour){
      var rgb = $('&lt;div style="color:#28e32a"&gt;');     // Use a non standard dummy colour to ease checking for edge cases
      var valid_rgb = "rgb(40, 227, 42)";
      rgb.css("color", colour);
      if(rgb.css('color') == valid_rgb &amp;&amp; colour != ':#28e32a' &amp;&amp; colour.replace(/ /g,"") != valid_rgb.replace(/ /g,""))
          return false;
      else
          return true;
  };
  </code></pre>