TechnicallyChris.com

Technical and Personal Ramblings of a Bostonian
  • Home
  • About Chris
  • Donate
  • Contact Chris
Home > ColdFusion > Validating a Hex Value in ColdFusion

Validating a Hex Value in ColdFusion

June 9th, 2006
Goto comments Leave a comment

I wrote the following for someone to help validate is a 6 character hex value is a valid RGB color (from #000000 to #FFFFFF). Hope it helps someone else. I’m always looking for better ways, if you have one, please leave a comment.

ValidHexColor.cfm

If you enjoyed this article or it helped you in any way, I’d appreciate it if you’d post a comment below to let me know. All code examples are for demonstration only and should be used at your own risk. I cannot accept liability for unexpected results.

Chris ColdFusion ColdFusion

Comments (2) Trackbacks (0) Leave a comment Trackback
  1. Timmy
    January 18th, 2007 at 12:47 | #1
    Reply | Quote

    Thanks for the code! I just made a quick variation and dropped it into a cfscript block to use some validation inline:


    if(Len(form.color))
    {
    form.color = ReReplace(form.color,'##','','all');
    if(ReFindNoCase('[^0-9a-fA-F]',form.color) OR Len(form.color) NEQ 6)
    error.color = 'Not a valid HTML Hex color';
    }

  2. Jim
    July 29th, 2008 at 15:15 | #2
    Reply | Quote

    May not change much, but you can combine the string length check, pound check, and HEX value check into one:

    Of course this allows for variable size HEX code. You could change the number in the braces to 6 so that it requires there to be 6 characters. (eg. replace {1,6} with {6})

  1. No trackbacks yet.
Subscribe to comments feed
Right Align Your Flash Form Submit Button Keeping ColdFusion Datasource Names Dynamic
RSS feed
  • Google
  • Youdao
  • Xian Guo
  • Zhua Xia
  • My Yahoo!
  • newsgator
  • Bloglines
  • iNezha

Sponsored By

Read my review of Mozy here.

Recent Posts

  • Just Bought the Google Nexus One
  • Seven Things I’ve Liked About Windows 7 in Seven Day
  • What’s Happened to Customer Service (Part 2)?
  • What’s Happened to Customer Service (Part 1)?
  • Capturing S.M.A.R.T. Hard Disk Data from WMI with AutoIt
  • Adjusting DCOM Settings via Script
  • How to Manually Call the Google Cache
  • RoboForm & RoboForm2Go Product Review
  • Updated PingCell Function for Excel
  • Creating Hyperlinks in Word and Excel Longer than 256 Characters

Categories

  • ColdFusion
  • Firefox
  • Google Nexus One
  • IIS
  • McAfee EE / SafeBoot
  • Microsoft Windows
  • Oracle
  • Random Code
  • Random Technology
  • Sports and Recreation
  • Subversion
  • The Untechnological

Archives

  • January 2010
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • October 2007
  • September 2007
  • August 2007
  • January 2007
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006

Meta

  • Register
  • Log in
PageRank
Top WordPress
Copyright © 2006-2010 TechnicallyChris.com
Theme by mg12. Valid XHTML 1.1 and CSS 3.