Print Page | Close Window

E-mail validation problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1372
Printed Date: 29 March 2026 at 10:15am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: E-mail validation problem
Posted By: vicky_c
Subject: E-mail validation problem
Date Posted: 26 March 2003 at 9:53am

Hi!

Could someone please help me with this script I am trying out?  It is supposed to validation the format of an e-mail address entered but it doesn't work and you can still register an account by having anything as ur e-mail address.

Here is the script:

.............................................................................................
<%
 'Save entered username and password 
 uid = Request.Form("uid")
 pass = Request.Form("pass")
 full = Request.Form("full")
 Email = Request.Form("email")
 ip = Request.Form("ip")
 
 if uid = "" then Response.redirect("empty.asp")
 if pass = "" then Response.Redirect("empty.asp")
 if full = "" then Response.Redirect("empty.asp")
 if Email = "" then Response.Redirect("empty.asp")
 
Dim checkemail
checkemail = 0 'Initializing checkemail to 0

'if the len is less than 5 then it can't be an email
'(i.e.: mailto:a@a.c - a@a.c )
If Len(session("email")) <= 5 Then
checkemail = 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.
checkemail = 1
Else
If InStr(1,session("email"), ".", 1) < 4 Then
'Must have a '.' too
checkemail = 1
End If
End If

If checkemail <> 0 then
'Well , if checkemail <> 0 then something
'must be wrong
response.write "Bad E-Mail..."
End If

 
 
  'Build connection
 set conn = server.CreateObject ("ADODB.Connection")
 conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\home\Default\zoebirkett.net\htdocs\cgi-bin\pro.mdb"
 set rs = server.CreateObject ("ADODB.Recordset")
 'Open all records
 rs.Open "SELECT * FROM admin", conn, 3, 3
   
 'Check if username doesn't already exist
 do while not rs.EOF
  if rs("uid")=uid then
   set rs=nothing
   set conn=nothing
   Response.Redirect("taken.asp")
  end if
  rs.MoveNext
 loop
  
 'Add a record
 rs.AddNew
 'Put username and password in record
 rs("uid")=uid
 rs("pass")=pass
 rs("full")=full
 rs("email")=email
 rs("ip")=ip
 'Save record
 rs.Update
 
 set rs=nothing
 set conn=nothing

 Response.Redirect("login.asp")

 
%>
.............................................................................................

I really appreciate any help anyone can give me!

Thanks,
Vicky  xxx




Replies:
Posted By: michael
Date Posted: 26 March 2003 at 12:21pm

I think the script is way too complex for just validating an email. One thing though, where does the session for email get set. You are declaring the variable email but it's not used, you are using session("email").
Anyway, if your server supports RegEx then do the following:

<%
Function CheckMail(strEmail)
Dim objRegExp , blnValid
Set objRegExp = New RegExp
objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
blnValid = objRegExp.Test(strEmail)
If blnValid Then
Response.Write "Valid Email Address"
Else
Response.Write "Invalid Email Address"
End If
End Function
%>

Now you can just check the email address with as easy syntax as:
<%CheckMail("validmail@email.com")%>

It would spit out Valid Email Address Thus in your case you would want to use the blnValid and if true then do your thing.



Posted By: MorningZ
Date Posted: 26 March 2003 at 2:32pm
haha, that http://www.regexlib.com - looks famaliar

great source for RegEx help for sure

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: michael
Date Posted: 26 March 2003 at 2:38pm
I got it from some other site some time ago, but I guess it is limited how an email validation can look :)


Posted By: vicky_c
Date Posted: 29 March 2003 at 4:19pm

Thanks so much for your help guys!

Michael, I used your code in the script and its still not working...I know I'm doing something wrong but I just can't think what .  Yes the "email" is called from the information the user enters in the previous page.  Would it help if I post up both pages?  Maybe the error is with the previous page?  I really don't know.

Once again thanks so much for your help!

Loadsa love,
Vicky  xxx

 

 

create account page________________________________________ 


<meta http-equiv="Content-Language" content="en-us">

<body>
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#569BE0" width="800" id="AutoNumber1">
  <tr>
    <td width="50%">
    <form method="POST" action="login_cr.asp">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" bordercolor="#E1F0FF" id="AutoNumber2" height="41">
        <tr>
          <td width="100%" bgcolor="#E1F0FF" height="21">
          <p align="left"><b><font face="Verdana" size="2" color="#000080">&nbsp;Create
          Account:</font></b></td>
        </tr>
        <tr>
          <td width="100%" height="19">
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="87">
            <tr>
              <td width="1%" height="87">&nbsp;</td>
              <td width="98%" height="87"><center>
              <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="350" id="AutoNumber4">
                <tr>
                  <td width="33%">
                  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5" height="116">
                    <tr>
                      <td width="32%" height="34"><b>
                      <font color="#569BE0" size="2" face="Verdana">User ID: </font></b>
                      <font color="#FF0000" size="1" face="Verdana">*</font></td>
                      <td width="68%" height="34">
                      <input name="uid" size="20" style="font-size: 10pt; font-family: Verdana; border: 1px solid navy; color:navy; background=white; float:left"> </td>
                    </tr>
                    <tr>
                      <td width="32%" height="34"><b>
                      <font color="#569BE0" size="2" face="Verdana">Password: </font></b>
                      <font color="#FF0000" size="1" face="Verdana">*</font></td>
                      <td width="68%" height="34">
                      <input name="pass" size="20" style="font-size: 10pt; font-family: Verdana; border: 1px solid navy; color:navy; background=white; float:left"></td>
                    </tr>
                    <tr>
                      <td width="32%" height="34"><b>
                      <font color="#569BE0" size="2" face="Verdana">Email: </font></b>
                      <font color="#FF0000" size="1" face="Verdana">*</font></td>
                      <td width="68%" height="34">
                      <input name="email" size="20" style="font-size: 10pt; font-family: Verdana; border: 1px solid navy; color:navy; background=white; float:left"></td>
                    </tr>
                    <tr>
                      <td width="32%" height="34"><b>
                      <font color="#569BE0" size="2" face="Verdana">Full Name: </font></b>
                      <font color="#FF0000" size="1" face="Verdana">*</font></td>
                      <td width="68%" height="34">
   &



Posted By: michael
Date Posted: 29 March 2003 at 5:19pm
Well you put in the function, but you are not calling it. After you got your email from the queryString just call it as follows. You do not even need to make the call if Email = "" ......   the RegExp does that.

CheckMail(Email)
If NOT blnValid THEN Response.Redirect("totherainbow.asp")
response.end

Function CheckMail(Email)
Dim objRegExp , blnValid
Set objRegExp = New RegExp
objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
blnValid = objRegExp.Test(Email)
End Function



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: vicky_c
Date Posted: 30 March 2003 at 1:19pm

Thanks so much Michael for your help!  I feel really bad and thick but, it's still not working.    this time instead of it accepting anything as valid its accepting nothing as valid!  Even proper e-mail addresses are sed to be wrong.

I'm really sorry about this!  Do you know what I've done wrong again?

Loadsa love,
Vicky xxx

 

 

<%
 'Save entered username and password 
 uid = Request.Form("uid")
 pass = Request.Form("pass")
 full = Request.Form("full")
 Email = Request.Form("email")
 ip = Request.Form("ip")
 
 if uid = "" then Response.redirect("empty.asp")
 if pass = "" then Response.Redirect("empty.asp")
 if full = "" then Response.Redirect("empty.asp")
 if Email = "" then Response.Redirect("empty.asp")

CheckMail(Email)
If NOT blnValid THEN Response.Redirect("totherainbow.asp")
response.end

Function CheckMail(Email)
Dim objRegExp , blnValid
Set objRegExp = New RegExp
objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
blnValid = objRegExp.Test(Email)
End Function

 

 
 
  'Build connection
 set conn = server.CreateObject ("ADODB.Connection")
 conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\home\Default\zoebirkett.net\htdocs\cgi-bin\pro.mdb"
 set rs = server.CreateObject ("ADODB.Recordset")
 'Open all records
 rs.Open "SELECT * FROM admin", conn, 3, 3
   
 'Check if username doesn't already exist
 do while not rs.EOF
  if rs("uid")=uid then
   set rs=nothing
   set conn=nothing
   Response.Redirect("taken.asp")
  end if
  rs.MoveNext
 loop
  
 'Add a record
 rs.AddNew
 'Put username and password in record
 rs("uid")=uid
 rs("pass")=pass
 rs("full")=full
 rs("email")=email
 rs("ip")=ip
 'Save record
 rs.Update
 
 set rs=nothing
 set conn=nothing
 
 

 Response.Redirect("login.asp")

 
%>



Posted By: michael
Date Posted: 30 March 2003 at 2:37pm

Sorry in this case I would do the processing withing the function. So just call it like CheckMail(email) and in the function add the following:

Function CheckMail(Email)
Dim objRegExp , blnValid
Set objRegExp = New RegExp
objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
blnValid = objRegExp.Test(Email)
If NOT blnValid THEN Response.Redirect "wherever.asp"
End Function

You can return some values but in your case there should be no need as you want to redirect a user anyway if they entered an invalid email address.



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: vicky_c
Date Posted: 30 March 2003 at 3:19pm

Omg!!!!!  It works!!!!

Thank you soooo much!!!  I'm so happy I could cry!!!  You have no idea how much less stressful you just made my life!!!!

Mwaaah!! xxxx

Right I need a drink to celebrate!  Thank you soooo much!  You're a complete Star!

God bless you!!!!!

Loads and loadsa love,
Vicky xxxxxxx



Posted By: michael
Date Posted: 30 March 2003 at 5:55pm
No problem

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net