Validating the email address
-5
Validating the email address
Function IsValidEmail(emailAddress)
'Declare variables
Dim ValidEmail, emailParts, iLoopCounter, emailChar, acceptableChars
ValidEmail = True 'set the default result to True
'acceptableChars are the characters that we will allow in our email
acceptableChars="abcdefghijklmnopqrstuvwxyz.-_@"
'use the Split function to create an array with the @ as the separator
'so if your email was test@tester.com the email would be split into an array
'with the first array element holding "test" and the second "tester.com"
emailParts = Split(emailAddress, "@")
'check to make sure that there is only 1 @ and that there are 2 parts
'remember arrays are zero based
'Using the UBound function will return the highest element in the array
'So if it's a valid email the UBound function will return 1, i.e. 0 start
if UBound(emailParts) <> 1 Then
ValidEmail = false
Else
'Check the length of each part of the email address
'first part can be just one character, 2nd part must be atleast 4
if Len(emailParts(0))<1 OR Len(emailParts(1))<4 Then
ValidEmail = false
End If
'check first character on the left part isn't a "." using Left function
if Left(emailParts(0), 1)="." Then
ValidEmail = false
End If
'check the last & 2nd character from right part using Right function
if Right(emailParts(1), 1) = "." OR Right(emailParts(1), 2) = "." Then
ValidEmail = false
End If
'check that there is a . in the second part of the email address - .com
if InStr(emailParts(1), ".") <= 0 Then
ValidEmail = false
End if
'check that there shouldn't be a _ in the second part of the email address
if InStr(emailParts(1), "_") >0 Then
ValidEmail = false
End if
End If
'loop through each character of email
For iLoopCounter = 1 to Len(emailAddress)
'Use Lcase & Mid functions, Mid function used to return each individual character
'in the email, and then Lcase converts it into lowercase
emailChar = Lcase(Mid(emailAddress, iLoopCounter, 1))
'Check if the emailAddress characters are acceptable
if InStr(acceptableChars, emailChar) = 0 and Not IsNumeric(emailChar) Then
ValidEmail = false
End if
Next
'check if there is 2 . in a row
if InStr(emailAddress, "..") > 0 Then
ValidEmail=false
End If
'check if there is @. in a row
if InStr(emailAddress, "@.") > 0 Then
ValidEmail=false
End if
IsValidEmail=ValidEmail
End function





http://www.dsc-services.be
set MXValidate = Server.CreateObject("Company.Emailvalidate")
emailaddress = Request.Form("emailaddress")
MXValidate.serveraddresses = "XXX.XXX.XXX.XXX","XXX.XXX.XXX.XXX"
MXValidate.ValidateIt(emailaddress,resultcode)
If resultcode = False Then
Response.Redirect("badAddress.html")
Else
'continue form processing...
End If
http://www.dsc-services.be
Set DNSobject = Server.CreateObject("Company.DNS")
Emailaddress = Request.Form("emailaddress")
TheDomainName = Mid(emailaddress, _
InStr(1,emailaddress,"@",vbTextCompare)+1,Len(emailaddress))
DNSobject.domain = thedomainname
DNSobject.server = "XXX.XXX.XXX.XXX"
goodorbad = DNSojbect.dolookup
'Keep in mind some DNS object may return something other than ""
If goodorbad = "" Then
Response.Redirect("badAddress.html")
Else
'continue form processing...
End If
peter.o'toole+foo@bar.com is a perfectly valid address, these scripts aren't very nice on these people :-D
Let's try to stop spreading this notion that emails are simple letters and numebrs only. If we're going to write email validation scripts, let's at least try and make them accessible.