Jump to content

Correct preg match ( preg_match | regular expression ) for url in php?


onedumbcoder

Recommended Posts

I cant get the right preg_match expression for a url

 

here is what i have and it does not work:

 

	if(!empty($website))
	{
		if(!preg_match('(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)', $website))
		{
			$websiteerror .= " Invalid website.";
		}
	}

Can someone please help me with this. I read the links and my if statement still does not work, I have tried all of them.

 

here what i have right now and it is not working.

 

	if(!empty($website))
	{
		if(!preg_match('/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/\\+\#%&=\?\-_]+$/i', $website))
		{
		{
			$websiteerror .= " Invalid website.";
			$erroroccured = 1;
		}
	}

 

 

when i went lets say  www.asdfsa.com if fails

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.