09. april 2002 - 13:21
#2
<%
'----------------------------------------------------------------------------------------------
' MailValidator 1.8.1, Dec. 28, 2000
'----------------------------------------------------------------------------------------------
' Called with ValidateEmail("email@adresse.dk")
' Returns True if the address is valid, False if it's not.
' The variable "V_Status" returns an error description (if any).
' Error reports and suggestions can be sent to: morten@borg.net
' The script is distributed as freeware.
'
' Example:
FrmMail = Request.Form("mailadd")
If ValidateEmail(" & FrmMail &") Then
Response.Write "The e-mail address is invalid."
Else
Response.Write "Error in the e-mail address.<BR>Error description: " & V_Status
End If
'----------------------------------------------------------------------------------------------
Dim V_EmailToValidate, V_Ats, V_InvalidDomains, V_Domain, V_ValidTLDs, V_ValidTLD, V_TLD, V_Exclude, V_i, V_Status, V_StatusLang
'---- Settings ----
'Choose a language for the error description:
'V_StatusLang = "us"
V_StatusLang = "dk"
'-------------------
'
' The first function is used for backwards compability with the old, Danish version
' and can therefore be deleted in most cases.
Function Valider(V_EmailToValidate)
Valider = ValidateEmail(V_EmailToValidate)
End Function
Function ValidateEmail(V_EmailToValidate)
ValidateEmail = True
V_EmailToValidate = LCase(V_EmailToValidate)
' (1) Check length '------------------------------------------------------------------------
If Len(V_EmailToValidate) < 5 Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "E-mail adressen er for kort." Else V_Status = "The e-mail address is too short."
Exit Function
End If
' (2) Must contain @ '----------------------------------------------------------------------
If InStr(V_EmailToValidate,"@") = 0 Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der mangler et ""@"" i e-mail adressen." Else V_Status = "There's missing an ""@"" in the e-mail address."
Exit Function
End If
' (3) Check for "@." og ".@" '--------------------------------------------------------------
If ((InStr(V_EmailToValidate,"@.") <> 0) OR (InStr(V_EmailToValidate,".@") <> 0)) Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der mŒ ikke v¾re et punktum lige op af et ""@"" i e-mail adressen." Else V_Status = "There can't be a period right next to a ""@"" in the e-mail address."
Exit Function
End If
' (4) Anything in front of the @ ? '--------------------------------------------------------
If Len(Left(V_EmailToValidate,InStr(V_EmailToValidate,"@") - 1)) = 0 Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der mangler noget foran ""@"" i e-mail adressen." Else V_Status = "There needs to be something in front of the ""@"" in the e-mail address."
Exit Function
End If
' (5) At least one "." (period) '-----------------------------------------------------------
If InStr(V_EmailToValidate,".") = 0 Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "E-mail adressen skal indeholde mindst eet punktum." Else V_Status = "The e-mail address must contain at least one period."
Exit Function
End If
' (6) Max. 3 characters after the last "." '------------------------------------------------
If (Len(V_EmailToValidate) - InStrRev(V_EmailToValidate,".") > 3) Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der er for mange tegn efter sidste punktum i e-mail adressen." Else V_Status = "There's too many characters after the last period in the e-mail address."
Exit Function
End If
' (7) Check for ".." '----------------------------------------------------------------------
If InStr(V_EmailToValidate,"..") <> 0 Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der mŒ ikke v¾re to punktummer lige op af hinanden i e-mail adressen." Else V_Status = "There can't be 2 periods right next to each other in the e-mail address."
Exit Function
End If
' (8) At least 2 charecters after the last "." '--------------------------------------------
If (Len(V_EmailToValidate) - InStrRev(V_EmailToValidate,".") < 2) Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der skal v¾re mindst to tegn efter sidste punktum i e-mail adressen." Else V_Status = "There must be at least 2 charecters after the last period in the e-mail address."
Exit Function
End If
' (9) No "_" after "@" '--------------------------------------------------------------------
If ((InStr(V_EmailToValidate,"_") <> 0) AND (InStrRev(V_EmailToValidate,"_") > InStrRev(V_EmailToValidate,"@"))) Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der mŒ ikke v¾re en underscore (_) efter ""@"" i e-mail adressen." Else V_Status = "There can't be an underscore (_) efter ""@"" in the e-mail address."
Exit Function
End If
' (10) Check for multiple "@" '-------------------------------------------------------------
V_Ats = 0
For V_i = 1 TO Len(V_EmailToValidate)
If Mid(V_EmailToValidate,V_i,1) = "@" Then
V_Ats = V_Ats + 1
End If
Next
If V_Ats > 1 Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "E-mail adressen indeholder for mange ""@""." Else V_Status = "The e-mail address contains too many ""@""."
Exit Function
End If
' (11) Check domain name '------------------------------------------------------------------
V_InvalidDomains = Array("hotmail.dk","hotmai.com","yahho.dk","hotmaile.com","mail1stofanet.dk","ofri.dk","post1.dk","post2.dk","post3.dk","post4.dk","post5.dk","post6.dk","post7.dk","post8.dk","fc.skolekom.dk","post9.dk","hommail.com","jupiipost.dk","forom.dk","furom.dk","frorum.dk","mail.forum.dk","mailforum.dk","forum.mail.dk","sol.ak","guld.dk","hormail.com","wanacoo.dk","sol.mail.dk","mail.tel.dk")
V_Domain = Right(V_EmailToValidate,(Len(V_EmailToValidate) - InStrRev(V_EmailToValidate,"@")))
For V_i = 0 TO UBound(V_InvalidDomains)
If V_Domain = V_InvalidDomains(V_i) Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "E-mail adressens dom¾ne er ugyldigt." Else V_Status = "The domain name of the e-mail address is incalid."
Exit Function
End If
Next
' (12) Check TLD '--------------------------------------------------------------------------
V_ValidTLD = False
V_ValidTLDs = Array("dk","com","edu","gov","int","mil","net","org","af","al","dz","as","ad","ao","ai","aq","ag","ar","am","aw","ac","au","at","az","bs","bh","bd","bb","by","be","bz","bj","bm","bt","bo","ba","bw","bv","br","io","bn","bg","bf","bi","kh","cm","ca","cv","ky","cf","td","cs","cl","cn","cx","cc","co","km","cg","ck","cr","ci","hr","cu","cy","cz","dj","dm","do","tp","ec","eg","sv","gq","er","ee","et","fk","fo","fj","fi","fr","gf","pf","tf","ga","gm","ge","de","gh","gi","gr","gl","gd","gp","gu","gt","gg","gn","gw","gy","ht","hm","va","hn","hk","hu","is","in","id","ir","iq","ie","im","il","it","jm","jp","je","jo","kz","ke","ki","kp","kr","kw","kg","la","lv","lb","ls","lr","ly","li","lt","lu","mo","mk","mg","mw","my","mv","ml","mt","mh","mq","mr","mu","yt","mx","fm","md","mc","mn","ms","ma","mz","mm","na","nr","np","nl","an","nc","nz","ni","ne","ng","nu","nf","mp","no","om","pk","pw","ps","pa","pg","py","pe","ph","pn","pl","pt","pr","qa","re","ro","ru","rw","kn","lc","vc","ws","sm","st","sa","sn","sc","sl","sg","sk","si","sb","so","za","gs","es","lk","sh","pm","sd","sr","sj","sz","se","ch","sy","tw","tj","tz","th","tg","tk","to","tt","tn","tr","tm","tc","tv","ug","ua","ae","gb","uk","us","um","uy","su","uz","vu","ve","vn","vg","vi","wf","eh","ye","yu","cd","zm","zr","zw")
V_TLD = Right(V_EmailToValidate,(Len(V_EmailToValidate) - InStrRev(V_EmailToValidate,".")))
For V_i = 0 TO UBound(V_ValidTLDs)
If V_TLD = V_ValidTLDs(V_i) Then
V_ValidTLD = True
Exit For
End If
Next
If NOT V_ValidTLD Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "E-mail adressens dom¾ne-endelse (f.eks. "".dk"" el. "".com"") er ikke korrekt." Else V_Status = "The domain-ending (eg. "".net"" or "".com"") of the e-mail address is invalid."
Exit Function
End If
' (13) Check each character '---------------------------------------------------------------
For V_i = 1 TO Len(V_EmailToValidate)
If NOT IsNumeric(Mid(V_EmailToValidate,V_i,1)) AND (LCase(Mid(V_EmailToValidate,V_i,1)) < "a" OR LCase(Mid(V_EmailToValidate,V_i,1)) > "z") AND Mid(V_EmailToValidate,V_i,1) <> "_" AND Mid(V_EmailToValidate,V_i,1) <> "." AND Mid(V_EmailToValidate,V_i,1) <> "@" AND Mid(V_EmailToValidate,V_i,1) <> "-" Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "E-mail adressen indeholder et eller flere ugyldige tegn." Else V_Status = "The e-mail address contains at least on invalid character."
Exit Function
End If
Next
' (14) Addresses to be excluded '-----------------------------------------------------------
V_Exclude = Array("jc@pc.dk")
For V_i = 0 TO UBound(V_Exclude)
If V_EmailToValidate = V_Exclude(V_i) Then
ValidateEmail = False
If V_StatusLang = "dk" Then V_Status = "Der kan ikke sendes til den valgte e-mail adresse da den er ekskluderet pga. misbrug." Else V_Status = "The e-mail address can't be used as it has been excluded due to inproper use."
Exit Function
End If
Next
End Function
%>