SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: regex valid ul

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex valid ul

    Hi Guys,

    I am trying to validate a user input url. the regex should only allow url starting with http://domain.com or www.domain.com or http://www.domain.com

    my current regex only allows for http://www.domain.com

    can somene help plz ??

    PHP Code:
    if(!preg_match("/^(http)+(:\\/\\/)+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i"$company_web)) {
                
    $is_error 1;
                
    $error_message .= '<li>you have typed an invalid company web address 1</li>';
                
    $error_count++;
            } 

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    filter_var('example.com'FILTER_VALIDATE_URL); 

  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Your current pattern also allows for httphttphttphttphttp://://://://://://://://://://://_.. as a "valid" URL. There have been many posts in this forum on the subject of validating URLs and my first suggestion would be to point you towards the search function, so you can see if anything already posted here will be useful to you.
    Salathe
    Software Developer and PHP Manual Author.


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
  •