It seems that you are matching with css color:
function isValidColor(str) { return str.match(/^#[a-f0-9]{6}$/i) !== null; }
Develop:
^ start of the match
# hash [a-f0-9] any letter from af and 0-9
{6} previous group is displayed exactly 6 times
$ end of match
i ignore case
source share