HeadAcheMike
asked on
regular expression help, validate url and extension
hi,
i have an expression that validates URLs but i need it modified so that it only allows certain file extenstions, or if you have another fresh example that will do fine
i need an expression that will only allow a url with a file name with one of the following extensions, jpg, jpeg, gif, png
for example
http://domain.com/picture.jpg - valid
http://domain.com/picture.php - invalid
http://domain.co.uk/folder/picture.jpg - valid
http://domain.co.uk/folder/ - invalid
etc etc
here is the function i currently have:
function valiurl($url) {
if (eregi("^((ht|f)tp://)((([ a-z0-9-]+( \.[a-z0-9- ]+)*(\.[a- z]{2,3}))| (([0-9]{1, 3}\.){3}([ 0-9]{1,3}) ))((/|\?)[ a-z0-9~#%& '_\+=:\?\. -]*)*)$", $url)) {
return true;
}
else {
return false;
}
}
any help will be much appreciated, thank you
i have an expression that validates URLs but i need it modified so that it only allows certain file extenstions, or if you have another fresh example that will do fine
i need an expression that will only allow a url with a file name with one of the following extensions, jpg, jpeg, gif, png
for example
http://domain.com/picture.jpg - valid
http://domain.com/picture.php - invalid
http://domain.co.uk/folder/picture.jpg - valid
http://domain.co.uk/folder/ - invalid
etc etc
here is the function i currently have:
function valiurl($url) {
if (eregi("^((ht|f)tp://)((([
return true;
}
else {
return false;
}
}
any help will be much appreciated, thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both and sorry for the delay responding
i will look at both suggested solutions tonight and award the points to the one that best suits my system
Thanks again, Mike
i will look at both suggested solutions tonight and award the points to the one that best suits my system
Thanks again, Mike
eregi("^(ht|f)tp://.+?\..+