www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Detect various web site link formats in textarea - no strip, no replace

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    7

    resolved [RESOLVED] 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.

    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.

    Ideas?

    Thanks.

  2. #2
    Join Date
    Feb 2013
    Posts
    7
    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)?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles