Hello
I am using a VBScript to try to validate the information input in a form. This is the code:
<%
'Function to Validate Email Address
Function ValidateEmail(email)
dim atCnt
ValidateEmail = false
if len(cstr(email)) < 7 then
ValidateEmail = true
elseif instr(email,"@"
= 0 then
ValidateEmail = true
elseif instr(email,"."
= 0 then
ValidateEmail = true
elseif len(email) - instrrev(email,"."
> 3 then
ValidateEmail = true
elseif instr(email,"_"
<> 0 and _
instrrev(email,"_"
> instrrev(email,"@"
then
ValidateEmail = true
else
atCnt = 0
for i = 1 to len(email)
if mid(email,i,1) = "@" then
atCnt = atCnt + 1
end if
next
if atCnt > 1 then
ValidateEmail = true
end if
for i = 1 to len(email)
if not isnumeric(mid(email,i,1)) and _
(lcase(mid(email,i,1)) < "a" or _
lcase(mid(email,i,1)) > "z"
and _
mid(email,i,1) <> "_" and _
mid(email,i,1) <> "." and _
mid(email,i,1) <> "@" and _
mid(email,i,1) <> "-" then
ValidateEmail = true
end if
next
end if
End Function
'Usage of the Function
if ValidateEmail(request.form("email"
) then
Reponse.write "Invalid Email Address"
else
Response.write "Valid Email Address"
End if
%>
The code refers to a form which has the following properties:
<align=center><table border=0 cellspacing=0 cellpadding=0 width="350">
<tr><td align="center" valign="top" width="350">
<form name="welcome" method="post" action="welcome1.asp">
</p>
<table bgcolor="#FF9900">
<tr><td align="center"><b><font face="courier" color="#FFFFFF" size=-2>Name</font></b>
</td>
<td align="center"><input type="text" name="user_name" size=12></td>
</tr>
<tr>
<td align="center"><b><font face="courier" color="#FFFFFF" size=-1>E-mail</font></b>
</td>
<td align="center"><input name="email" type=text size=12><TYPE=HIDDEN NAME="RECIPIENT" VALUE="info@grafik1.net"></td>
</tr>
<tr><br>
<td align="center"><b><font face="courier" color="#FFFFFF" size=-1>Message</font></b>
</td></tr>
</table>
<table><tr>
<td align="center"><textarea name="message" cols="20" rows="3"></textarea>
</td></tr>
</table>
In the above code, welcome1.asp (which works) refers to a 'Thank you + name' page which appears after the user has clicked on the submit button. For some reason, this still appears when I deliverately input a wrongly formatted e.mail address.
Is the problem something to do with the VBScript, or is it more likely to lie in the "input name" and/or "input type" values of the form itself?
I would be grateful for any suggestions.
Many thanks
LaPluma
I am using a VBScript to try to validate the information input in a form. This is the code:
<%
'Function to Validate Email Address
Function ValidateEmail(email)
dim atCnt
ValidateEmail = false
if len(cstr(email)) < 7 then
ValidateEmail = true
elseif instr(email,"@"
ValidateEmail = true
elseif instr(email,"."
ValidateEmail = true
elseif len(email) - instrrev(email,"."
ValidateEmail = true
elseif instr(email,"_"
instrrev(email,"_"
ValidateEmail = true
else
atCnt = 0
for i = 1 to len(email)
if mid(email,i,1) = "@" then
atCnt = atCnt + 1
end if
next
if atCnt > 1 then
ValidateEmail = true
end if
for i = 1 to len(email)
if not isnumeric(mid(email,i,1)) and _
(lcase(mid(email,i,1)) < "a" or _
lcase(mid(email,i,1)) > "z"
mid(email,i,1) <> "_" and _
mid(email,i,1) <> "." and _
mid(email,i,1) <> "@" and _
mid(email,i,1) <> "-" then
ValidateEmail = true
end if
next
end if
End Function
'Usage of the Function
if ValidateEmail(request.form("email"
Reponse.write "Invalid Email Address"
else
Response.write "Valid Email Address"
End if
%>
The code refers to a form which has the following properties:
<align=center><table border=0 cellspacing=0 cellpadding=0 width="350">
<tr><td align="center" valign="top" width="350">
<form name="welcome" method="post" action="welcome1.asp">
</p>
<table bgcolor="#FF9900">
<tr><td align="center"><b><font face="courier" color="#FFFFFF" size=-2>Name</font></b>
</td>
<td align="center"><input type="text" name="user_name" size=12></td>
</tr>
<tr>
<td align="center"><b><font face="courier" color="#FFFFFF" size=-1>E-mail</font></b>
</td>
<td align="center"><input name="email" type=text size=12><TYPE=HIDDEN NAME="RECIPIENT" VALUE="info@grafik1.net"></td>
</tr>
<tr><br>
<td align="center"><b><font face="courier" color="#FFFFFF" size=-1>Message</font></b>
</td></tr>
</table>
<table><tr>
<td align="center"><textarea name="message" cols="20" rows="3"></textarea>
</td></tr>
</table>
In the above code, welcome1.asp (which works) refers to a 'Thank you + name' page which appears after the user has clicked on the submit button. For some reason, this still appears when I deliverately input a wrongly formatted e.mail address.
Is the problem something to do with the VBScript, or is it more likely to lie in the "input name" and/or "input type" values of the form itself?
I would be grateful for any suggestions.
Many thanks
LaPluma