Jump to content

reg expression for URL


TheOne17

Recommended Posts

I have been using this function to validate an URL from field

 

function checkURL($url)

{

return eregi("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$", $url);

}

 

The only problem is that is won't accept URL's with a hyphen in

e.g.

www.northlincs.gov.uk/20-21

 

Does anyone know how to modify this to work with hyphens or have a good reg exp for URL's that will work with hyphens

 

Thanks

 

Link to comment
Share on other sites

<?php
$url="http://www.google.co.uk";
if(eregi("^(http://|https://|ftp://|
http://www.)+[a-z0-9\_\-]{1,25}\.+
([a-z0-9\_\-]{1,3}|.+[a-z0-9\_\-]{1,3}\.
+[a-z0-9\_\-]{1,3})$", $url)
){
echo" your url is: $url";
}else{
echo"sorry wrong url: $url format";
}
?>

 

This will do what ever but only for the index of the domain not what your trying to do if

you want to your need to alter the code and add another or | ok.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.