Hi Guys, My friend gave me this idea about validating color code. I can write a regular expression but need to write for Hex Color, RGB, and color name as well, which is very difficult.
//Create a temporary dom element, I create span
var span = document.createElement('span');
//Set background color to the value you want to give
span.style.backgroundColor = colorValue;
//If not valid color, backgroundColor will be a "" (empty) string, which is a falsy value
return span.style.backgroundColor ? true: false;