Skip to main content
March 16, 2013
Answered

Need Help With REFind

  • March 16, 2013
  • 7 replies
  • 1077 views

I have a form filed and need to make sure that there is not URL's being passed through it.  I would like to search the field and test it for "http" and/or "www", if those charters are present I would like to send it to a special page that handels it and then abort the rest of the script.

Can anyone help me with this?

Thanks!

Nick

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer BreakawayPaul

    See if this helps.  It's from my regex cheat sheet.

    <cfset regex = "^(http://|www)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$" />

    Then :

    #refind(regex,"your_string")#

    Should return 1 if there's a match, or 0 if there isn't.

    7 replies

    BreakawayPaul
    BreakawayPaulCorrect answer
    Inspiring
    March 17, 2013

    See if this helps.  It's from my regex cheat sheet.

    <cfset regex = "^(http://|www)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$" />

    Then :

    #refind(regex,"your_string")#

    Should return 1 if there's a match, or 0 if there isn't.

    March 17, 2013

    Paul,

    You were spot on with your post, I can't thank you enough for your help!

    Have the code in place and it is working like a charm.

    Nick

    March 17, 2013

    Paul,

    After a bit more testing I noticed that your regex was not working.  I had to use the following code to getthe script to work:

    <cfset stringToSearch = '#form.xxx#'>

    (Notice, I had to use single quotes instead of double quotes, the double quotes were killing me!)

    <p>

    <cfset foundit = '#FindNoCase("http",stringToSearch)#'>

    <cfif foundit gt 0>

            <cflocation url="http://www.xxx.com">

            <cfabort>

    </cfif>

    Had to use:

    #refind("http","your_string")#

    Instead of:

    #refind(regex,"your_string")#

    Have no idea about Regular Expressions, wish I understood what your code is doing so that I could work on it to get it to work but all I know is that the script works this way and I will take it!  :-)

    Thanks again for your help!

    Nick