7 Replies Latest reply on Mar 17, 2013 6:46 PM by Cooperstown.Com

    Need Help With REFind

    Cooperstown.Com

      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

        • 1. Re: Need Help With REFind
          BreakawayPaul Level 2

          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.

          • 2. Re: Need Help With REFind
            Cooperstown.Com Level 1

            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

            • 3. Re: Need Help With REFind
              Cooperstown.Com Level 1

              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

              • 4. Re: Need Help With REFind
                BreakawayPaul Level 2

                Hi Nick,

                 

                Do you have an example case that it doesn't match?  You asked for one that would find a URL starting with either http:// or www.  If you only need it to find ones starting with http://, then that's a simpler regex.

                • 5. Re: Need Help With REFind
                  Cooperstown.Com Level 1

                  Paul,

                   

                  I wanted to use your code but when I uesed #refind(regex,"your_string")# and tested it it did not catch any of the test data that I used.  I used the following code and it worked with all of the test data:

                   

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

                  <cfif foundit gt 0>

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

                          <cfabort>

                  </cfif>

                   

                  It should not matter that I used FindNoCase instead of ReFind?

                   

                  If I used the following do you think it should have worked?

                   

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

                  <cfif foundit gt 0>

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

                          <cfabort>

                  </cfif>

                   

                  I liked you code because it also tested for www and that would have been good to test for!

                   

                  Thanks for all your help!

                   

                  Nick

                  • 6. Re: Need Help With REFind
                    BreakawayPaul Level 2

                    Tweaked the regex.  It should find a url with or without the http://

                    <cfset regex = "^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$" />

                    <cfset my_search_string = "http://forums.adobe.com/">

                     

                    <cfset foundit =refind(regex,my_search_string>

                    <cfif foundit gt 0>

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

                            <cfabort>

                    </cfif>

                    If you are passing a variable as the second argument in refind(), leave the quotes out.  If it's a string, then it needs to be quoted.

                    • 7. Re: Need Help With REFind
                      Cooperstown.Com Level 1

                      Paul,

                       

                      I will work on it tomorrow and get back to you.

                       

                      Thanks again!

                       

                      Nick