Check if variable is numeric

Hi there, i am trying to create a cfif statement that checks that a form entry is numeric, however I am having issues with it…

At the moment i am using the following code on the form action page

<cfif rc.releaseDate neq int(rc.releaseDate)>
There is a problem
<cfelse>
Everything is fine, add form info into database
</cfif>

However if the form field rc.releaseDate contains text instead of a number, I recieve the error message…

The value “whatever text i entered” cannot be converted to a number

Any have any ideas? Many thanks

The Int() method isn’t for making a decision it’s used for conversion
http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000511.htm

Have you tried isNumeric()?

Cheers for response…

For some reason if I do this

&lt;cfset blah = "1"&gt;

&lt;cfif blah EQ isNumeric(blah)&gt;
yes
&lt;cfelse&gt;
no
&lt;/cfif&gt;

The output on the browser is yes…

But if I do this on the action page of the form…

&lt;cfset blah = "#FORM.number#"&gt;

&lt;cfif blah EQ isNumeric(blah)&gt;
yes
&lt;cfelse&gt;
no
&lt;/cfif&gt;

It outputs no on the browser…is there some issue when submitting numbers using forms?

Thanks

Two things wrong here:

  1. isNumeric() will return a true or false (boolean) value so no blah is not equal to true/false so it will fail everytime.

  2. You’re declaring blah as a string “1” not a number blah = 1 but I guess that’s just because it’s an example here :slight_smile:

<cfif isNumeric(blah)>
TRUE
<cfelse>
FALSE
</cfif>

should do the trick.

Example in the livedocs:
http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt1135.htm

Yes, thanks for your help…that has worked…