Page 1 of 1

[SOLVED] Regex giving me problems

Posted: Tue Sep 05, 2006 7:45 pm
by HiddenS3crets
I use this function to validate a URL

Code: Select all

function validateURL($url) {
        if(preg_match("/^http:\/\/www\.+[A-Za-z0-9]+\.a-z{2,4}/", $url))
                return true;
        else
                return false;
}
The problem is that it always returns false, no matter what I pass in. It should return true if $url is something like "http://www.somesite.com"

There must be a problem with the regex, but i'm not sure what it is (still in the process of learning regex).

Any ideas where the bug is?

Posted: Tue Sep 05, 2006 8:13 pm
by feyd
hint: you're missing something around the latter "a-z"

Posted: Tue Sep 05, 2006 8:23 pm
by HiddenS3crets
is it [ and ]? I tried doing that and it still returned false :(

Posted: Tue Sep 05, 2006 8:27 pm
by feyd
All I can guess is you put them in the wrong spot(s).