Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

prevent links in text area

Posted on 2005-05-04
17
Medium Priority
?
211 Views
Last Modified: 2012-05-05
Hi,

What's the best way to disallow links in textarea inputs?

Thanks

Dbb
0
Comment
Question by:DBB
  • 6
  • 6
  • 3
  • +1
17 Comments
 
LVL 19

Expert Comment

by:DreamMaster
ID: 13927072
Probably the best way, is to search for a part in the string that resembles any type of link and strip that part of it.

Regards,
Max.
0
 
LVL 2

Author Comment

by:DBB
ID: 13927123
Thought so,

I just wandered if there was a tag to use or something

Thanks

Dbb
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 13927197
Nope, there's nothing like a "strip links from textareas" tag...unfortunately.. ;)

Regards,
Max.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:DBB
ID: 13927260
Didn't think so, ah well...

Dbb
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13931179
this will stop all links in the texarea

<script>
function stripLinks(obj){
 reg=/<a[^>]+>[^>]+<\/a>/gi
 obj.value=obj.value.replace(reg,'')
}
</script>

<textarea onblur="stripLinks(this)" onkeyup="this.onblur()" cols="40" rows="15"></textarea>
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13931201
reg=/< *a[^>]+>[^>]+< *\/a *>/gi  

is slightly better
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13943405
That probably won't stop:

this:

<div style="cursor: pointer; color: blue" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration=''" onclick="location.href='http://kiddanger.com/'">kiddanger.com</div>

or this:

<span style="cursor: pointer; color: blue" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration=''" onclick="location.href='http://kiddanger.com/'">kiddanger.com</span>

or this:

<select name="goaway" onchange="location.href=this.options[this.selectedIndex].value">
<option value="" selected>Where do you want to go today?</option>
<option value="http://microsoft.com/">microsoft</option>
<option value="http://experts-exchange.com/">experts exchange</option>
<option value="http://hp.com/">hp</option>
</select>

or this:

<img style="cursor: pointer; border: 5px outset blue" onmouseover="this.style.border='5px inset blue'" onmouseout="this.style.border='5px outset blue'" src="http://i.microsoft.com/h/en-us/r/ms_masthead_ltr.gif" onclick="location.href='http://microsoft.com/'" title="who's your daddy?" />

http://kiddanger.com/lab/ee/talinks.html
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 13943412
That's why I would strip out the http:// parts....

Regards,
Max.
0
 
LVL 2

Author Comment

by:DBB
ID: 13943530
Anyone got a quick script that'll strip the entire url?

Thanks

Dbb
0
 
LVL 19

Accepted Solution

by:
DreamMaster earned 800 total points
ID: 13943550
There's no script that will always strip an entire URL...there can be so many things in the URL that you don't know of...you can however make sure they won't work as a URL...by stripping of the http:// part...

Regards,
Max.
0
 
LVL 2

Author Comment

by:DBB
ID: 13943584
can you not strip between <a href> and </a>?
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 13943593
Well..you could...but what if the link is done the way kiddanger described? Then the link is still there...

Regards,
Max.
0
 
LVL 2

Author Comment

by:DBB
ID: 13943604
Sorry, just realised that after I posted...
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13949689
I think this was a good discussion.  I didn't realize the difficulty until I started looking at it.  I don't know why, but I chose a long time ago to just show the text in either <xmp> or <pre></pre> and this renders the links to merely visual.
0
 
LVL 2

Author Comment

by:DBB
ID: 13950229
Thanks Kiddanger, your input is much appreciated. As is from everyone else.

Thanks guys

Dbb
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 13950972
Glad to have been helpfull :)

Regards,
Max.
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13951711
You're welcome, DBB.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question