CFLib.org – Common Function Library Project

IsColor(color)

Last updated May 9, 2009

author

Jon Hartmann

Version: 0 | Requires: CF8 | Library: StrLib

Description:
Checkes to see if a color is a valid 3 or 6 character hex color, or one of the ColdFusion safe color keywords (aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow).

Return Values:
returns a Boolean

Example:

Is #fff a valid color? <cfdump var="#IsColor('##fff')#"><br />
Is #0fff a valid color? <cfdump var="#IsColor('##0fff')#"><br />
Is #000fff a valid color? <cfdump var="#IsColor('##000fff')#"><br />
Is blue a valid color? <cfdump var="#IsColor('blue')#"><br />
Is brown a valid color? <cfdump var="#IsColor('brown')#">

Parameters:

Name Description Required
color string of color to test Yes

Full UDF Source:

<!---
 Checkes to see if a color is a valid 3 or 6 character hex color, or one of the ColdFusion safe color keywords.
 
 @param color 	 string of color to test (Required)
 @return returns a Boolean 
 @author Jon Hartmann (jon.hartmann@gmail.com) 
 @version 0, May 9, 2009 
--->
<cffunction name="IsColor" access="public" output="false" returntype="boolean">
    <cfargument name="color" type="string" required="true" />
        
    <cfset var local = structNew() />
    <cfset local.colorNames = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,white,yellow" />
    <cfset local.regex = "^(##([\dA-F]{3}|[\dA-F]{6})|([\dA-F]{3}|[\dA-F]{6}))$" />
    <cfset local.returnValue = false />
        
    <cfif listFind(local.colorNames, arguments.color) OR arrayLen(REMatchNoCase(local.regex, arguments.color)) gt 0>
        <cfset local.returnValue = true />
    </cfif>
    
    <cfreturn local.returnValue />
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson