Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
The following is a part of a form validation code. The code segment is supposed to validate URL's.


PHP
else if($Key == "Website" || $Key == "Destination" || $Key == "Source")
							{
								if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]/i",	$Data[$Key]))
								{
									$Error[$Key] = "Invalid URL.";
									$Return = 1;
								}
							}



Debugging effort shows that the code reports an error when it reads the following URL from form inputs:


HTML
<input type="hidden" value="GetAffiliatelink.php" name="Destination"/>
								<input type="hidden" value="ProductAffiliate.php#Promote%20School%20Pedestal" name="Source"/>


Please why is it stating that the url's are not valid. I have been looking at the code for hours and can't find any bug. Can someone kindly help me give it a look?
Posted
Comments
Peter_in_2780 25-Dec-15 2:58am    
Suggestion: Grab a copy of Expresso, set up your regex, feed in the URL and look at the detailed output.
Gbenbam 26-Dec-15 15:29pm    
ok. Will try it thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900