1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Pregmatch help for validating URLs

Discussion in 'PHP' started by krishmk, Sep 23, 2010.

  1. #1
    if (!preg_match ('/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}'.'((:[0-9]{1,5})?\/.*)?$/i', $url))
    {
    // Display error
    }
    PHP:
    The above pregmatch works just fine except in the following case:

    when i use "http://www.bounce" it bypasses (without the domain extension like .com, .net or .org etc.)
    however "http://www.bouncer" triggers the error as intended

    so here is the glitch - any domain name less than 7 characters bypasses the pregmatch check (when entered without the domain extension). I would like to fix this. Appreciate your help.
     
    krishmk, Sep 23, 2010 IP
  2. jaholden

    jaholden Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Unless your requirements are unusual, why not use PHP's own validation? For example:

    filter_var($url, FILTER_VALIDATE_URL);
     
    jaholden, Sep 23, 2010 IP