Regex - validate URL?

Discussion in 'Programming' started by Triexa, Dec 10, 2008.

  1. #1
    Regex is definitely not my strong front and I am trying to validate that the input is a valid URL. A search on google yields tons of variations, all of which seem to be very basic and fail a valid url quite easily.

    Does anyone have a reliable pattern to validate a url?

    Appreciate it!
     
    Triexa, Dec 10, 2008 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Always use this site for regex expressions of all types:

    http://regexlib.com/

    Peace,
     
    Barti1987, Dec 10, 2008 IP
  3. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #3
    You should check for
    
     ^[url]http://[.]+[/url][\.] atleast.
    
    Code (markup):
     
    it career, Dec 10, 2008 IP
  4. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #4
    $urlpattern = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
    Code (markup):
    One of several weapons in my arsenal. ;)
     
    harrisunderwork, Dec 11, 2008 IP
  5. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    That seems to validate
    - no domain extension?

    Edit: nevermind, I guess that is a valid url...
     
    Triexa, Dec 12, 2008 IP