I am trying to validate URLs uploaded to my database. If the URL field is left empty validation should be skipped. If the URL field has >= 1 character in it then validation should carry on. However the URL's provided are always incorrect despite me adhering to the validation rules during posting. What could be going wrong? Thanking you in advance.
CODE
<?
$num_char=strlen($fileurl);
$num_char2=strlen($youtubeurl);
$url = "|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i";
if ( $num_char >= 1 && preg_match($url, $fileurl)) {
echo "You must supply a file URL in a valid format (for example: <i>http://en.wikipedia.org/wiki/Image:Meissner_effect_p1390048.jpg</i>). Click <a href=\"addtopic.php\">here</a> to start again.<p>";
exit ();
} else {;}
if ( $num_char2 >= 1 && !preg_match($url,$youtubeurl)) {
echo "<div align=\"left\" class=\"style9\">You must supply a YouTube URL in a valid format (for example <i>http://www.youtube.com/watch?v=mG5VFBfHPf0</i>). <p>
<img src=\"../images/youtubeurl.jpg\"><p>
Click <a href=\"addtopic.php\">here</a> to start again.<p></div>
";
exit ();
} else {;}
?>
This post has been edited by jeansymolanza: 28 Aug, 2008 - 04:55 PM