Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ereg on a URL 1

Status
Not open for further replies.

steijssen

Programmer
Mar 25, 2001
92
BE
Hi,

I'm curious to know how the ereg expression would look like when you want to validate a URL (the text only, it doesn't need to realy exist, but 'htp:/ww.website.kom' should not be accepted :)
 
really, the only part you can expect to validate via regexp is http:// ftp:// etc. You cannot truely validate a domain because ww.domain.com and and [anything].[anything].[etc].[tld] are all valid.

So, to validate http:// you just do:

if(!eregi("^ {
//not a good url
}

Chad. ICQ: 54380631
online.dll
 
Below is the posix regular expression an url has to match to.
Good luck.

eregi("([0-9a-z]([-\\.]?[0-9a-z])*\\.)+[a-z]{2,}:)[0-9]+)?(/[-/.=_&0-9a-z]*)?(\\?[-.=_&0-9a-z]*)?$", $site) mcvdmvs
-- "It never hurts to help" -- Eek the Cat
 
but remember that even that model does not allow for all posibilities.

At my work, we have over 100 domains and some of them are so off-beat that the posix regexp does not work.

chad. ICQ: 54380631
online.dll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top