For example:
AA33FF = valid hex color
Z34FF9 = invalid hex color (has Z in it)
AA33FF11 = invalid hex color (h
function validColor(color){
var $div = $("");
$div.css("border", "1px solid "+color);
return ($div.css("border-color")!="")
}
https://gist.github.com/dustinpoissant/22ce25c9e536bb2c5a2a363601ba261c
Note: This requires jQuery
This works for ALL color types not just hex values. It also does not append unnecessary elements to the DOM tree.