Coldfusion's isNumeric(): A different approach
Comments: 0 Stars : 0
My friend, Aldwin, has a different approach in solving the isNumeric() problem mentioned in my previous post. Here is his solution for the module that he's working on (I've slightly modified it to remove sensitive information):
<cfset str = "-256.">
<cfset acceptonly = "1,2,3,4,5,6,7,8,9,0,.,-">
<cfif listfind(acceptonly, str, ",") gt 0>
This is not a valid number.
<cfelse>
This is a valid number.
</cfif>
<cfset acceptonly = "1,2,3,4,5,6,7,8,9,0,.,-">
<cfif listfind(acceptonly, str, ",") gt 0>
This is not a valid number.
<cfelse>
This is a valid number.
</cfif>
Please note that this is only applicable for certain (preferrably pre-validated) inputs. This will not flag an error for inputs such as "8.-.16-" or "...32.256"
Back to entries Comment on this entry