Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - E-mail validation problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

E-mail validation problem

 Post Reply Post Reply Page  12>
Author
vicky_c View Drop Down
Newbie
Newbie


Joined: 14 March 2003
Location: Scotland
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote vicky_c Quote  Post ReplyReply Direct Link To This Post Topic: E-mail validation problem
    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.: 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

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 26 March 2003 at 2:32pm
haha, that looks famaliar

great source for RegEx help for sure
Contribute to the working anarchy we fondly call the Internet
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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 :)
Back to Top
vicky_c View Drop Down
Newbie
Newbie


Joined: 14 March 2003
Location: Scotland
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote vicky_c Quote  Post ReplyReply Direct Link To This Post 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">
   &

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
vicky_c View Drop Down
Newbie
Newbie


Joined: 14 March 2003
Location: Scotland
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote vicky_c Quote  Post ReplyReply Direct Link To This Post 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")

 
%>

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.