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;
    }
}

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

Created by Raymond Camden / Design by Justin Johnson