E-mail Filter - Postet den (1066 Views)
Junior Member
mafifi
Innlegg: 308
308
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
   
 Sidestørrelse 
Postet den
Junior Member
mafifi
Innlegg: 308
308
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
%>
Regards,

Mo
Postet den
Support Moderator
Doug G
Innlegg: 6493
6493
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
Postet den
Average Member
cripto9t
Innlegg: 881
881
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
    _-/Cripto9t\-_
Postet den
Junior Member
mafifi
Innlegg: 308
308
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.
Regards,

Mo
 
Du må legge inn en melding