Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 E-mail Filter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mafifi
Junior Member

USA
308 Posts

Posted - 15 August 2009 :  18:04:22  Show Profile  Reply with Quote
I would like to block out users with certain e-mail domains (i.e. gmail, hotmail) from submitting a form on my site. I would like to do that on the server side to prevent users from tampering with JavaScript. I do not want to use a database driven one and am thinking about using an array. If someone can point me to a sample code that would be great.

Regards,

Mo

mafifi
Junior Member

USA
308 Posts

Posted - 15 August 2009 :  20:03:09  Show Profile  Reply with Quote
I put this toghther. If it can be improved, please let me know.


<%
DIM EmailArray(4)
	EmailArray(0) = "yahoo"
	EmailArray(1) = "hotmail"
	EmailArray(2) = "gmail"
	EmailArray(3) = "netzero"
	EmailArray(4) = "test"

strEmail = "MyEmail@MyCompany.com"
' strEmail = Request.Form("Email")

For i = 0 to UBound(EmailArray)
	If InStr(1,strEmail,EmailArray(i),1) Then
		Flag = True
	End If
Next

If Flag = True Then
	Response.Write "Bad E-mail"
ELSE
	Response.Write "Good E-mail"
End If
%>

Regards,

Mo
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 16 August 2009 :  01:07:08  Show Profile  Reply with Quote
If it were me, I'd reconsider using a db. One advantage to a database-driven list is you can use your db query tool to add or remove entries without having to edit and upload files, assuming you're not using Access, anyway. Although even with access you could use an app like table editor to make db changes.


======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 16 August 2009 :  09:33:45  Show Profile  Reply with Quote
For i = 0 to UBound(EmailArray)
	If InStr(1,strEmail,EmailArray(i),1) Then
		Flag = True
	End If
Next


Just looking at it, I think you need to exit the loop once it's true. Because it will always come out false unless it's the last one in the list.
For i = 0 to UBound(EmailArray)
	If InStr(1,strEmail,EmailArray(i),1) Then
		Flag = True
                exit for
	End If
Next

    _-/Cripto9t\-_
Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 16 August 2009 :  12:19:06  Show Profile  Reply with Quote
quote:
Originally posted by cripto9t

For i = 0 to UBound(EmailArray)
	If InStr(1,strEmail,EmailArray(i),1) Then
		Flag = True
	End If
Next


Just looking at it, I think you need to exit the loop once it's true. Because it will always come out false unless it's the last one in the list.
For i = 0 to UBound(EmailArray)
	If InStr(1,strEmail,EmailArray(i),1) Then
		Flag = True
                exit for
	End If
Next




I think the following will improve it a little.

<%
DIM EmailArray(4)
	EmailArray(0) = "@yahoo.com"
	EmailArray(1) = "@hotmail.com"
	EmailArray(2) = "@gmail.com"
	EmailArray(3) = "@netzero.com"
	EmailArray(4) = "@test.com"

strEmail = "MyEmail@MyCompany.com"
' strEmail = Request.Form("Email")

For i = 0 to UBound(EmailArray)
	If InStr(1,strEmail,EmailArray(i),1) Then
		Flag = True
                Exit For
	End If
Next

If Flag = True Then
	Response.Write "Bad E-mail"
ELSE
	Response.Write "Good E-mail"
End If
%>


This way you eleminate a domain as "MyTest" from being flagged as a bad domain.

Regards,

Mo
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.47 seconds. Powered By: Snitz Forums 2000 Version 3.4.07