我错了什么?(表格确认) [英] What am I getting wrong?(Form validation)

查看:96
本文介绍了我错了什么?(表格确认)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是表单验证代码的一部分。代码段应该验证URL。





  else  if($ Key ==   Website ||  $ Key  ==  目的地 ||  $ Key  ==  来源
{
if (!preg_match( / \b |(:( ?: HTTPS FTP?):\?/ \ / | www\) - α-Z0-9 +&安培; @#\ /%=〜_ |!: ,。;] * [ - a-zA-Z0-9 +& @#\ /%= ~_ |] / i,$ Data [$ Key]))
{
$错误[$ Key] = 无效的网址。;
$ Return = 1 ;
}
}







调试工作表明代码报告错误当它从表单输入中读取以下URL时:





 <  输入    type   = 隐藏    value   =  GetAffiliatelink.php   名称  = 目的地  /  >  
< 输入 < span class =code-attribute> type = hidden value = ProductAffiliate.php #Advote%20School%20Pedestal name = 来源 / >





请注意,为什么网址无效。我一直在看代码几个小时,找不到任何错误。有人可以帮我看看吗?

解决方案

Key == 网站 ||


Key == 目的地 ||


Key == Source
{
if (!preg_match( / \b(?:(?:https?| ftp):\ / \ / | www \。)[ - a-z0-9 +& ?!; @#\ /%=〜_ |:;] * [ - α-ZA-Z0-9 +&安培; @#\ /%=〜_ |] / I

The following is a part of a form validation code. The code segment is supposed to validate URL's.


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:


<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?

解决方案

Key == "Website" ||


Key == "Destination" ||


Key == "Source") { if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]/i",


这篇关于我错了什么?(表格确认)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆