JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 16th, 2013, 05:09 PM
we5inelgr we5inelgr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 106 we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 24 m 29 sec
Reputation Power: 1
Question 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.

Reply With Quote
  #2  
Old February 16th, 2013, 09:10 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 34 m 55 sec
Reputation Power: 69
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.

Reply With Quote
  #3  
Old February 16th, 2013, 10:41 PM
we5inelgr we5inelgr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 106 we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level) 
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.

Reply With Quote
  #4  
Old February 17th, 2013, 01:34 AM
we5inelgr we5inelgr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 106 we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level) 
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.

Reply With Quote
  #5  
Old February 17th, 2013, 09:31 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 34 m 55 sec
Reputation Power: 69
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?

Reply With Quote
  #6  
Old February 18th, 2013, 12:04 PM
we5inelgr we5inelgr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 106 we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level) 
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.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Detect various web site link formats in textarea - no strip, no replace

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap