Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion - Remove all non-numeric values from a list?

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?

like image 971
jyoseph Avatar asked Jan 14 '11 19:01

jyoseph


2 Answers

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")>
like image 172
Sean Coyne Avatar answered Oct 24 '22 01:10

Sean Coyne


<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" />

like image 31
Bradley Moore Avatar answered Oct 23 '22 23:10

Bradley Moore