regular expression validation with urls

Discussion in 'JavaScript' started by tdd1984, Sep 22, 2007.

  1. #1
    Hey guys I have a quick question I need to validate a url such as

    http://www.domain.com

    or

    http://tyler.subdomain.com

    It always needs to be in this format because it will insert into the database

    does any one have a javascript code they can give me fo this? I'm not famaliar with regexp like I am php and sql.


    basically what I'm trying to do is to make sure they insert with http://www.domain.com or http://subdomain.subdomain.com so it always goes in that format before insert into mysql because I'm going to check mysql before people sign up to make sure no duplicate domains go into the database? what would be the best way of doing this?

    Also http://www.domain.com/myfolder/ is aloud too, I just need to make sure http://www. is the url field when there signing up, but the problem is the sub domain, how would I do this?
     
    tdd1984, Sep 22, 2007 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Logic Ali, Sep 27, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Here is a simplified version, with a few fixes such as allowing hyphens in URLs

    ~^http://([a-z-]+\.){2,}[a-z]{2,6}/?$~i
    Code (markup):
    tdd, why aren't you allowing http://domain.com ? (without the www. )
     
    krt, Sep 27, 2007 IP