Utility Function: IsColor()
- October 26, 2008 5:29 AM
- ColdFusion, Utility Function
- Comments (0)
I think that there are some valid colors that the REGEX is going to reject, but here is another one that I find useful:
<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>