loading...

April 29, 2011

ColdFusion RegEx White List Example

I needed to build a function that would strip out characters in event information because, otherwise it would break a JSON feed. Here is what I used:


<cffunction name="jsonSafe" access="private">
  <cfargument name="str" type="string" required="true">
  <cfset newStr = reReplace(arguments.str, '[^[:alnum:][:space:]$=;.?!\/&"''`():,[]{}_-]', '_','all')>
  <cfreturn newStr>
</cffunction>
Posted in DevelopmentTaggs: