Re: Regex for Validating URL
| From: | Curt Zirzow | Date: | Fri, 03 Sep 2004 02:13:25 +0000 |
| Subject: | Re: Regex for Validating URL | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-195667@lists.php.net to get a copy of this message | ||
* Thus wrote Nick Wilson:
>
> * and then Manuel Lemos declared....
> > >Does anyone have the regex to make sure an http address is full and
> > >without error? like http://www.example.com
> >
> > Usually I use this expression:
> >
> >
> > '^(http|https)\://(([-!#\$%&\'*+.0-9=?A-Z^_`a-z{|}~^?]+\.)+[A-Za-z]{2,6})(\:[0-9]+)?(/)?/'
> >
>
> DING DING DING!! Ladies and gentleman, i think we have a winner! ;-)
um.. ok.. i guess you consider http://?#.zzzzzz/ a full url without
error. This answer could have been easily answered if you simply
answered the question that wanted to know this.
>
> You know guys? I think you all take this a bit too seriously,
> perdanticness (is there such a word?) is all well and good for an FBI
> agent but I stand by the claim that my original question really was
> rather simple.
No its not that simple, unless you have the magical 8 ball:
http://woohoo/
http://foo@bar.com/
http://foo:user@bar.com/
http://port.deprived:8230/
http://another-one-bites-the-dust.com/
http://forever_we_could.go-but.not-done.com/
http://another.one.so.where/at/a/location/
http://a.sub.domain.crazy.person.com/
ftp://woah.switch.protocols.on.us.com/
myown://custom.protocol.or-could.be-any_standard.whatchamacallit/
http://neverneverland:842/~chickensrule/
file://c:/windows/hatred.ini
So which one is full and without error?
Curt
--
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about. No, sir. Our model is the trapezoid!