1

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?

6
  • Use a regular expression Commented Oct 28, 2013 at 11:34
  • The contents of an input (its value) won't be rendered as HTML within it. Commented Oct 28, 2013 at 11:35
  • @Bernhard this may work, but it wouldn't work very well for poorly formed URLs as in the OPs example. If you start each URL with http: ftp: or https: then you could regex it easily. Commented Oct 28, 2013 at 11:35
  • does website name will be always the last part of string Commented Oct 28, 2013 at 11:36
  • 1
    possible duplicate of How to replace plain URLs with links? Commented Oct 28, 2013 at 11:37

2 Answers 2

2
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?

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.