E-mail Filter

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/68863?pagenum=1
05 November 2025, 03:52

Topic


mafifi
E-mail Filter
15 August 2009, 18:04


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.

 

Replies ...


mafifi
15 August 2009, 20:03


I put this toghther. If it can be improved, please let me know.
Code:

<%
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
%>
Doug G
16 August 2009, 01:07


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.
cripto9t
16 August 2009, 09:33


Code:
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.
Code:
For i = 0 to UBound(EmailArray)
If InStr(1,strEmail,EmailArray(i),1) Then
Flag = True
exit for End If
Next
mafifi
16 August 2009, 12:19


Originally posted by cripto9t
Code:
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.
Code:
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.
Code:

<%
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.
© 2000-2021 Snitz™ Communications