• 0

PHP Regular Expression Problem


Question

I found this Regular Expression that validates a url, but for some reason it's not working with my php. I'm getting a php error at the line where the regexp is. I got the regexp here at the Regular Expression Library - http://regexlib.com/...?regexp_id=1121. What am I doing wrong? Any help would be greatly appreciated. Thanks.

	
//Check to make sure sure that a valid website is submitted

if(trim($_POST['website']) == '') {
$websiteError = 'You forgot to enter your website.';
$hasError = true;
} else if (!preg_match('/^((([hH][tT][tT][pP][sS]?|[fF][tT][pP])\:\/\/)?([\w\.\-]+(\:[\w\.\&%\$\-]+)*@)?((([^\s\(\)\<\>\\\"\.\[\]\,@;:]+)(\.[^\s\(\)\<\>\\\"\.\[\]\,@;:]+)*(\.[a-zA-Z]{2,4}))|((([01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}([01]?\d{1,2}|2[0-4]\d|25[0-5])))(\b\:(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)\b)?((\/[^\/][\w\.\,\?\'\\\/\+&%\$#\=~_\-@]*)*[^\.\,\?\"\'\(\)\[\]!;<>{}\s\x7F-\xFF])?)$/i', trim($_POST['website']))) {
$websiteError = 'You entered an invalid website address.';
$hasError = true;
} else {
$website = trim($_POST['website']);
}

[/CODE]

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.