• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need Help With REFind

Guest
Mar 16, 2013 Mar 16, 2013

Copy link to clipboard

Copied

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

Views

951

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Mar 16, 2013 Mar 16, 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.

Votes

Translate

Translate
Contributor ,
Mar 16, 2013 Mar 16, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 16, 2013 Mar 16, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 16, 2013 Mar 16, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 17, 2013 Mar 17, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 17, 2013 Mar 17, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 17, 2013 Mar 17, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 17, 2013 Mar 17, 2013

Copy link to clipboard

Copied

LATEST

Paul,

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

Thanks again!

Nick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation