BobDroid
BobDroid

Reputation: 1898

How to change the entered text as hyperlink in the textbox?

How to display the text as hyperlink if the user entered in the text box...

For example if the user entered the text as

"my website name is google.com"...and submit it,

i have to show that text as "my website name is google.com"

Is there any plugin available for this or any simple script is enough?

Upvotes: 1

Views: 405

Answers (2)

Rupert Madden-Abbott
Rupert Madden-Abbott

Reputation: 13278

This is usually called "linkify" which I guess is a bit difficult to Google for if you don't know that.

Here is a jQuery plugin that will do this for you.

Upvotes: 1

subZero
subZero

Reputation: 5176

function replaceURLWithHTMLLinks(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp,"<a href='$1'>$1</a>"); 
}

Thanks to: How to replace plain URLs with links?

Upvotes: 2

Related Questions