Asp classic InStr()asp经典表单字段验证
我正在尝试使用以下命令检查表单字段中的有效电子邮件地址:Asp classic InStr()asp经典表单字段验证,asp-classic,Asp Classic,我正在尝试使用以下命令检查表单字段中的有效电子邮件地址: if Request ("email") = "" then bError = true ElseIf Instr(1, email," ") <> 0 Then bError = true ElseIf InStr(1, email, "@", 1) < 2 Then bError = true else */go to success pag
if Request ("email") = "" then
bError = true
ElseIf Instr(1, email," ") <> 0 Then
bError = true
ElseIf InStr(1, email, "@", 1) < 2 Then
bError = true
else
*/go to success page*/
如果请求(“电子邮件”)=”则
贝罗=真
ElseIf Instr(1,电子邮件“”)0然后
贝罗=真
ElseIf InStr(1,电子邮件,“@”,1)<2然后
贝罗=真
其他的
*/转到成功页面*/
但是,如果电子邮件地址中有空格,它仍然通过验证。所以我的问题是,如何使用此方法检查空格?最好使用正则表达式
最好使用正则表达式来实现这一点
忘了其他的事情吧,简单点
Dim strEmail
Dim intErrors
intErrors = 0
strEmail = REQUEST("email")
strEmail = Trim(strEmail)
if strEmail = "" then intErrors = intErrors +1;
if instr(strEmail," ") > 0 then intErrors = intErrors +1;
if instr(strEmail,".") = 0 then intErrors = intErrors +1;
if instr(strEmail,"@") < 2 then intErrors = intErrors +1;
' Put as many test conditions as you want here
if intErrors = 0 then GotoSuccessPage
昏暗的街道邮件
暗中断器
中断=0
strEmail=请求(“电子邮件”)
strEmail=修剪(strEmail)
如果strEmail=“”,则intErrors=intErrors+1;
如果instr(strEmail,“”)>0,则intErrors=intErrors+1;
如果instr(strEmail,“.”=0,则intErrors=intErrors+1;
如果instr(strEmail,“@”)<2,则intErrors=intErrors+1;
'在此处放置您想要的任意多个测试条件
如果intErrors=0,则转到成功页面
忘掉所有其他的东西,简单点
Dim strEmail
Dim intErrors
intErrors = 0
strEmail = REQUEST("email")
strEmail = Trim(strEmail)
if strEmail = "" then intErrors = intErrors +1;
if instr(strEmail," ") > 0 then intErrors = intErrors +1;
if instr(strEmail,".") = 0 then intErrors = intErrors +1;
if instr(strEmail,"@") < 2 then intErrors = intErrors +1;
' Put as many test conditions as you want here
if intErrors = 0 then GotoSuccessPage
昏暗的街道邮件
暗中断器
中断=0
strEmail=请求(“电子邮件”)
strEmail=修剪(strEmail)
如果strEmail=“”,则intErrors=intErrors+1;
如果instr(strEmail,“”)>0,则intErrors=intErrors+1;
如果instr(strEmail,“.”=0,则intErrors=intErrors+1;
如果instr(strEmail,“@”)<2,则intErrors=intErrors+1;
'在此处放置您想要的任意多个测试条件
如果intErrors=0,则转到成功页面
是的,我知道reg ex会更好,但我不能在这种情况下使用它。为什么不呢?您只是将地址传递给一个函数。是的,我知道reg ex会更好,但我不能在这种情况下使用它。为什么不呢?您只是将地址传递给一个函数。您首先需要为名为“email”的变量分配请求值:email=request(“email”)
。您首先需要为名为“email”的变量分配请求值:email=request(“email”)
。
Function IsEmail(sCheckEmail)
Dim SEmail, NAtLoc
IsEmail = True
SEmail = Trim(sCheckEmail)
NAtLoc = InStr(SEmail, "@")
If Not (nAtLoc > 1 And (InStrRev(sEmail, ".") > NAtLoc + 1)) Then
IsEmail = False
ElseIf InStr(nAtLoc + 1, SEmail, "@") > NAtLoc Then
IsEmail = False
ElseIf Mid(sEmail, NAtLoc + 1, 1) = "." Then
IsEmail = False
ElseIf InStr(1, Right(sEmail, 2), ".") > 0 Then
IsEmail = False
End If
End Function
Dim strEmail
Dim intErrors
intErrors = 0
strEmail = REQUEST("email")
strEmail = Trim(strEmail)
if strEmail = "" then intErrors = intErrors +1;
if instr(strEmail," ") > 0 then intErrors = intErrors +1;
if instr(strEmail,".") = 0 then intErrors = intErrors +1;
if instr(strEmail,"@") < 2 then intErrors = intErrors +1;
' Put as many test conditions as you want here
if intErrors = 0 then GotoSuccessPage