IsWebSafeColor(hexColor)
Last updated November 06, 2001
Version: 1 | Requires: CF5 | Library: UtilityLib
Description:
Returns true if the given color is a web safe hexadecimal color. IsWebSafeColor accepts a 6 digit hexadecimal color as an agument. It returns true if the color is in the 216 color web safe pallette. If not, it returns false.
Return Values:
Returns a Boolean value.
Example:
<CFSET Color1="3366cc">
<CFSET Color2="c0c0c0">
<cfoutput>
Is #Color1# a web safe color? #YesNoFormat(IsWebSafeColor(Color1))#<BR>
Is #Color2# a web safe color? #YesNoFormat(IsWebSafeColor(Color2))#<BR>
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
hexColor | Hex color representation to validate. | Yes |
Full UDF Source:
/**
* Returns true if the given color is a web safe hexadecimal color.
*
* @param hexColor Hex color representation to validate.
* @return Returns a Boolean value.
* @author Eric Carlisle (ericc@nc.rr.com)
* @version 1, November 6, 2001
*/
function IsWebSafeColor(hexColor){
/* Establish list of web safe colors */
Var safeList = "00,33,66,99,cc,ff";
/* Strip out poundsigns from argument. */
Var tHexColor = replace(hexColor,'##','','ALL');
/* Initialize i */
Var i=0;
/* Loop over r,g,b hex values */
for (i=1; i lte 5; i=i+2){
/* Set result to FALSE if a color isn't web safe. */
if (listFindNoCase(safeList,mid(tHexColor,i,2)) eq 0){
return False;
}
}
return True;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016