CFLib.org – Common Function Library Project

IsHexColor(hexInput)

Last updated July 15, 2013

author

Tony Brandner

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Boolean check for a valid hexidecimal color. Thanks to Eric Carlisle (IsWebSafeColor).

Return Values:
Returns a Boolean.

Example:

<CFOUTPUT>
003366, #IsHexColor('003366')#<br>
aabbcc, #IsHexColor('aabbcc')#<br>
ffee, #IsHexColor('ffee')#<br>
eeffgg, #IsHexColor('eeffgg')#
</CFOUTPUT>

Parameters:

Name Description Required
hexInput Hex value you want to validate. Yes

Full UDF Source:

/**
 * Returns true if valid hexadecimal color.
 * 
 * @param hexInput 	 Hex value you want to validate. (Required)
 * @return Returns a Boolean. 
 * @author Tony Brandner (tony@brandners.com) 
 * @version 1, July 15, 2013 
 */
function IsHexColor(hexInput) {
  var cleanHexInput = replace(hexInput,'##','','ALL');
  if (Len(ReReplace(cleanHexInput, "[0-9abcdefABCDEF]", "","ALL")) eq 0 and Len(cleanHexInput) gt 5) {
    return True;
  } else {
      return False;
    }
}
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