Rip's Domain

IsValid weirdness

Posted in ColdFusion by rip747 on October 1, 2006

Ok this has been stumping the crap out of me for quite some time and I’m wondering if anyone else has seen this problem.

It all has to do with IsValid() and using the “integer” validation. From my understanding an “integer” means a whole number and “numeric” means a float (has decimal places in it). With that said, I have an init() method that look like this:

<cffunction name=”init” access=”public” returntype=”ProgramAd” output=”false”>
<cfargument name=”id” type=”string” required=”true”>
<cfif IsValid(“integer”,>
<cfset ReadObj(>
<cfreturn this>

Basically I pass in a string and if it’s a valid integer it will create the object and load the information in. If it isn’t, it just return a created object to me. Pretty basic stuff. Well here’s the kicker, when a pass in the value of “24” to the init() method from another CFC’s method, it won’t run the ReadObj() method. BUT if I change the IsValid() to “numeric” it works. Everything works cool if I try to create the object directly from a unit test template I have. I can’t figure this out and I’m wondering if anyone else has run into this. The real wacky thing is that I have this exact init() method in other CFCs and it works fine.

Anyone have an answer to this?


I did some searching around the net and found a post by Ray which describes a bug found in IsValid() ‘s “integer” validation. The thing is, the post is from July 2005, so you think that this would be fixed by now. Thanks again Adobe.


3 Responses

Subscribe to comments with RSS.

  1. Javier said, on October 1, 2006 at 11:06 pm

    I just tried this out to see what I would get and I got it working fine. I had the function output the id to make sure that the cfif was executing and it did. Have you tried passing in a numeric type value instead of a string to see if it gets rid of the problem?? I tested it out with the string value of 24.

  2. Julian Halliwell said, on October 2, 2006 at 3:06 am

    I would look at the code that’s calling the init function in this case and see what it’s actually passing. I’ve found that if a call is made within a cfloop tag, even though I’m outputting an integer as the loop index, CF casts it as a float under the hood and that’s what ends up being passed in and tested by IsValid(). Curiously, it doesn’t happen using a cfscript loop. See the LiveDocs for IsValid where I posted an example (currently right at the bottom).

  3. rip747 said, on October 2, 2006 at 8:41 am


    I know, like I said before, it’s weird. The same code works in other CFCs that I have, it was only in the one CFC that it was causing an issue.


    I must of spent an hour looking over the code and trying to figure out what was causing the issue. In the end I just did a global find and replace and set Isvalid(“integer”) to IsValid(“numeric”).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: