I have a list of IDs being passed through the URL. I want to do some sanitizing before running a query based on those IDs. I have this:
<cfset URL.ID = ReReplaceNoCase(URL.ID,"[^0-9]","","ALL")>
But I realize that's stripping the comma out also. Is there a simple way to remove non numeric values from a list in Coldfusion?
Why not just add a comma to your regex?
<cfset URL.ID = ReReplaceNoCase(URL.ID,"[^0-9]","","ALL")>
becomes
<cfset URL.ID = ReReplaceNoCase(URL.ID,"[^0-9,]","","ALL")>
<cfscript>
//Test Case
URL.ID= "abc,12,3,zoiui fdsoaiu ,323333";
//URL.ID= "12,3,323333"
URL.ID= reReplace( URL.ID , "([^0-9,]+,)" , "" , "all" );
</cfscript>
That being said, you'd want to put this in a <cfqueryparam .. list= "true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With