DEV Community

Cover image for isValidHexString ColdFusion UDF
James Moberg
James Moberg

Posted on

isValidHexString ColdFusion UDF

While working on my ColdFusion colorTools CFC, I wondered if isValid() supported a "hex" type since "guid" & "UUID" both rely on validating hexadecimal numbers... and the answer is no.

NOTE: I've added some new features to colorTools, but will write about them next week after I add some demo & test scripts.

Validating hex strings isn't difficult, but some values may be prefixed with "#" or "0x". Hex is also used for many other things beyond color codes, but I wanted to optionally & explicitly test for 6 character string values when accepting hex color values. I believe that this UDF covers all the requirements. (If it doesn't, let me know.)

Source Code

https://gist.github.com/JamoCA/c4079d7c813b0ad3d1a28cfc7551c355

Top comments (0)