Validating a Hex Value in ColdFusion
June 9th, 2006
I wrote the following for someone to help validate is a 6 character hex value is a valid RGB color (from #000000 to #FFFFFF). Hope it helps someone else. I’m always looking for better ways, if you have one, please leave a comment.

Thanks for the code! I just made a quick variation and dropped it into a cfscript block to use some validation inline:
if(Len(form.color))
{
form.color = ReReplace(form.color,'##','','all');
if(ReFindNoCase('[^0-9a-fA-F]',form.color) OR Len(form.color) NEQ 6)
error.color = 'Not a valid HTML Hex color';
}
May not change much, but you can combine the string length check, pound check, and HEX value check into one:
Of course this allows for variable size HEX code. You could change the number in the braces to 6 so that it requires there to be 6 characters. (eg. replace {1,6} with {6})