Jump to content

validating url


chris_s_22

Recommended Posts

im trying to validate url's sent to me by a form

the url's im collecting are for placing banners on my site

so the url's are the link to there site and url of where there banner is

 

URL's ARE BROKEN INTO PARTs PROTOCOL/SUBDOMAIN/DOMAIN NAME/DIRECTORY/FILE

 

SO FAR I GOT

 if(!preg_match("/^http://www.[a-z0-9-].[a-z]{2,3}[a-z0-9/.] $/i", $_POST[url]))

 

This checks the form feild url

1) make sure http://www. is present (i dont see why it should be any different for the purpose of my use)

i wll be placing a warning on my form page that the urls must contains this

 

2) Then my code checks it consists of only letters,numbers,dashes/hythens i read these are the only characters a domain name can be

also they must start with a letter or number so how do i make that possible?

 

3) the next part makes sure theres a .

4) the next part makes sure it consists of only letter of 2-3 characters long

this only alows things such as .com or .ru

How do i alow multiple for example .co.uk

5) i then want to make the rest optional but to alow

letter/numbers/for directories . for start of ext

 

can anyone help me tweak my code to satisfy my needs but to be as strict as possible.

 

also knowing what my code is going to be checking is there any genuine urls that the code would refuse

or is there anything i need to know

Link to comment
https://forums.phpfreaks.com/topic/183148-validating-url/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.