The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
Detect various web site link formats in textarea - no strip, no replace
Discuss Detect various web site link formats in textarea - no strip, no replace in the JavaScript Development forum on Dev Shed. Detect various web site link formats in textarea - no strip, no replace JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 16th, 2013, 05:09 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 106
 
Time spent in forums: 1 Day 24 m 29 sec
Reputation Power: 1
|
|
Detect various web site link formats in textarea - no strip, no replace
Hi all,
I'd like to detect, but not remove, not replace/strip, various formats for web site url's. Such as:
http://www.a.com
http://a.com
http:// www . a . com
http : // www a dot com
www.a.com
www . a . com
www dot a dot com
I've tried these, but they don't work:
Code:
var strFindWebSites=/^\(?[http]\)?[\. ]?[www][\. ]?[com]$/g;
if (strFindWebSites.test(theForm.theTextArea.value)) {
...
Code:
var strFindWebSites=/^\(?([http])\)?[\. ]?([www])[\. ]?([com])$/g;
if (strFindWebSites.test(theForm.theTextArea.value)) {
...
Code:
var strFindWebSites=/^\(?(http)\)?[\. ]?(www)[\. ]?(com)$/g;
if (strFindWebSites.test(theForm.theTextArea.value)) {
...
I realize that there are so many ways that people could enter a web site address, and I'm not trying to capture every possible way. Simply trying to capture the more common ways, and those that would include a space in them.
Ideas?
Thanks.
|

February 16th, 2013, 09:10 PM
|
 |
Contributing User
|
|
|
|
|
It looks like your wanting domain forwards or domain error handling; but this is not JavaScript... that does this. You could try to create a "catch all" in you htaccess file; to redirect the urls to your home page or an error page or where ever you want them to go.
|

February 16th, 2013, 10:41 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 106
 
Time spent in forums: 1 Day 24 m 29 sec
Reputation Power: 1
|
|
|
Thanks for the reply.
I'm not looking for domain forwards or domain error handling.
Just wanting to detect if anyone has inputed any textarea information that contains a web site address, as above.
|

February 17th, 2013, 01:34 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 106
 
Time spent in forums: 1 Day 24 m 29 sec
Reputation Power: 1
|
|
Update:
I've gotten this to work, just not sure this is the "best" way to approach this:
Code:
var strFindWebSites=["www", "w w w", "http", "h t t p", "href", "h r e f", ".com", "dot com", ".net", "dot net"];
var searchExp = new RegExp(strFindWebSites.join("|"),"gim");
if (searchExp.test(theForm.theTextArea.value)) {
...
I also realize that there is a chance that someone might type in something other than a web address with "polka dot netting" <-- That would be caught by "dot net"
How could I find the whole word string "dot net" only (in this case)? 
Last edited by we5inelgr : February 17th, 2013 at 01:36 AM.
|

February 17th, 2013, 09:31 PM
|
 |
Contributing User
|
|
|
|
Quote: | Originally Posted by we5inelgr I also realize that there is a chance that someone might type in something other than a web address with "polka dot netting" <-- That would be caught by "dot net"
How could I find the whole word string "dot net" only (in this case)?  |
You could check the string length; if it is below a specific number... use regex. Otherwise, skip over the text in the string/html or whatever.
Just wondering... what are you going for, with this? Are you trying to strip out spam domains, for an end user post or are you doing this for advertising or something else?
|

February 18th, 2013, 12:04 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 106
 
Time spent in forums: 1 Day 24 m 29 sec
Reputation Power: 1
|
|
|
Ah yes. Great idea.
This is just to flag entries for potential follow-up.
Thanks.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|