SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: validating URLs

  1. #1
    SitePoint Evangelist Alchemist's Avatar
    Join Date
    Aug 2006
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    validating URLs

    Hello,

    I'm looking for a reg exp function that will validate URLs submitted by users. I looked around extensively but found nothing I really liked. for example, take a look at this pattern:

    Code:
    (((ht|f)tp(s?):\/\/)|(www\.[^ \[\]\(\)\n\r\t]+)|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})\/)([^ \[\]\(\),;"'<>\n\r\t]+)([^\. \[\]\(\),;"'<>\n\r\t])|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})

    it will accept URLS such as www.dom>ain.com. is this supposed to be ok? PHP gurus, what do you use to validate URLs?

    thanks

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I use:
    http://www.php.net/manual/en/ref.filter.php

    PHP Code:
    var_dumpfilter_var('example.com'FILTER_VALIDATE_URLFILTER_FLAG_SCHEME_REQUIRED FILTER_FLAG_HOST_REQUIRED) ); # Fasle 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Evangelist Alchemist's Avatar
    Join Date
    Aug 2006
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the info. however, it looks like you have to have access to some kind of command line to enable those set of functions, and I'm currently on a shared hosting setup.

    any other alternatives in the meantime?

    thanks

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2007
    Location
    In the blogosphere
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use this
    Code:
    /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    bLueFrogX's Blog - Random Ramblings of a NEET Techie ★


Bookmarks

Posting Permissions

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