Avg. Rating 4.0

Problem

You have a user input that generates a list of values. You'd like to validate for types available in ColdFusion's isValid function

Solution

Loop through the list and use the built in isValid() function alongside a desired "validation type"

Detailed explanation

<cffunction name="isValidList" access="public" output="false" returntype="boolean">
     <cfargument name="type" type="string" required="yes">
     <cfargument name="listIn" type="string" required="yes">
     <cfargument name="Delim" type="string" required="no" default=",">
     
     <cfset var listItem = "">

    <cftry>

          <cfloop list="#arguments.listIn#" index="listItem" delimiters="#arguments.Delim#">
               <cfif NOT isValid(arguments.type,listItem)>
                    <cfreturn false>
               </cfif>
          </cfloop>

          <cfreturn true>

          <cfcatch type="any">
          <!--- in the case an improper type is passed --->
               <cfreturn false>
          </cfcatch>

     </cftry>

</cffunction>

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes