Link to home
Start Free TrialLog in
Avatar of hefterr
hefterrFlag for United States of America

asked on

IsValid for URL validation

Hi,
Is it me or is the Coldfusion (v8.01) "isValid" function kind of lame validating a URL?

It seems to me that almost anything following "http://" comes up as valid.  For example:

<cfif isValid("URL", "http://...")>
good url <br />
<cfelse>
bad URL<br />
</cfif>

Open in new window


Or

<cfif isValid("URL", "http://x")>
good url 2 <br />
<cfelse>
bad URL 2<br />
</cfif>

Open in new window


What's up with this function?

Thanks in advance,
hefterr
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hefterr

ASKER

Hi agx,
Do I check for cfhttp.statusCode = "200 OK"?

I was going to use Isvalid first before using CFHTTP.  And I am adding the "http://" in front of the user "web site address" from the form.  So I see no real reason to use Isvalid.  I guess?
Yep, 200 OK.

Well you could use isValid as a pre-check, to skip url strings that are obviously malformed, but that's about all it'll buy you.
Avatar of hefterr

ASKER

Hi agx,
Thanks for the answers.

If I can ask a related (sort of) design option.  We have a form that a user will enter a URL of an article found on the web.  The design is to have the user "omit http://".  Is this OK or can this lead to trouble using CFHTTP?
I think it's better to be consistent - whichever way you choose. That said cfhttp usually does okay with or without the http. But if you're worried about it, you could always validate the values on the backend and add the http:// if it's missing.

<cfif left(trim(theURL), 7) neq "http://">
      <cfset theURL = "http://"& theURL>
</cfif>