SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validate url regex

    Any idea why this function doesn't work...

    PHP Code:
    function ValidateURL($url)
        {
            if(!
    preg_match('/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?'$url))
            {
                return 
    false;
            } 
            else 
            {
                return 
    true;
            }

        } 
    I get the following error:

    Warning: preg_match() [function.preg-match]: Unknown modifier '~' in /Applications/MAMP/htdocs/domain.co.uk/public_html/classes/user.class.php on line 556

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Shouldn't the two / before the two ~ be escaped?

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Shouldn't the two / before the two ~ be escaped?
    Hi - I just tried that, now i'm getting:

    Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in /Applications/MAMP/htdocs/domain.co.uk/public_html/classes/user.class.php on line 556

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    You delimite the regex with / at the beginning, you have to put a / at the end too.


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
  •