我有一个简单的表单,可以让用户输入促销代码和电子邮件地址,以便按照以下方式注册电子邮件。但目前它不能正确验证电子邮件。验证电子邮件地址表格提交
有一个包含文件doreferral.asp;检查他们输入的代码是否存在于促销代码表中,并检查该电子邮件地址是否已存在。
我已添加emailValidate以检查电子邮件地址是否有效,如果不是,请告知用户<%= sys_message%>。
但是,它目前阻止真正的电子邮件,所以验证无效。 :S
我的doreferral.asp看起来像这样;
<%
Code = replace(request.Form("Code"),"'","")
Email = replace(request.Form("Email"),"'","")
sys_message = ""
submission = ""
''//Check the submitted code against existing ones in the database
set conn = server.CreateObject("ADODB.connection")
conn.open(application("DATABASE"))
qs = "SELECT COUNT(AgentReferralCode) AS 'CountCodes' FROM Customers WHERE AgentReferralCode = '" & Code & "'"
set rs = conn.Execute(qs)
CountCode = rs("CountCodes")
set rs = nothing
conn.close
set conn = nothing
If(CountCode < 1) Then
sys_message = sys_message & "<p class='err'>The agent code does not exist.</p>"
End If
''//Check to see if the email address is valid
Dim emailValidate
emailValidate = 0 'Initializing goby to 0
''//if the len is less than 5 then it can't be an email
''//(i.e.: [email protected])
If Len(session("Email")) <= 5 Then
emailValidate = 1
End If
If InStr(1, session("Email"), "@", 1) < 2 Then
'If we find one and only one @, then the
'email address is good to go.
emailValidate = 1
Else
If InStr(1,session("Email"), ".", 1) < 4 Then
'Must have a '.' too
emailValidate = 1
End If
End If
If emailValidate <> 0 then
sys_message = sys_message & "<p class='err'>The email address is not valid.</p>"
End If
''//Check the submitted email against existing ones in the database
set conn = server.CreateObject("ADODB.connection")
conn.open(application("DATABASE"))
qs = "SELECT COUNT(ReferredEmail) AS 'Count' FROM TenantReferral WHERE ReferredEmail = '" & Email & "'"
set rs = conn.Execute(qs)
countEmail = rs("Count")
set rs = nothing
conn.close
set conn = nothing
If(countEmail >= 1) Then
sys_message = sys_message & "<p class='err'>This email address has already been referred.</p>"
End If
''//Only Process the SQL if there is no sys_message
If(sys_message = "") Then
SQLfields = SQLfields & "ReferredCode, "
SQLvalues = SQLvalues & "'"& Trim(Code) &"', "
SQLfields = SQLfields & "ReferredEmail"
SQLvalues = SQLvalues & "'"& Trim(Email) &"'"
SQL = SQL & "INSERT into TenantReferral ("& SQLfields &") VALUES ("& SQLvalues &")"
'response.Write(SQL)
set conn = server.CreateObject("ADODB.connection")
conn.open application("DATABASE")
SET rs = conn.execute(SQL)
[Send email code]
sys_message = sys_message & "<p class='ok'>Thank you for your referral.</p>"
submission = "ok"
'response.Redirect("referral.asp")
End If
%>
我想知道是否有人可以帮助调试emailValidate功能来检查电子邮件地址是否有效?
谢谢。
之前已经询问过。见例如http://stackoverflow.com/questions/161342/is-there-a-php-library-for-email-address-validation – sleske 2009-10-08 02:12:30
从窗体插入值到你的方式查询,可以导致SQL注入.. 。 始终使用SQL参数! – Amirshk 2009-10-08 02:13:19