Avatar billede nogetfx Nybegynder
09. april 2002 - 12:54 Der er 10 kommentarer og
2 løsninger

Kalde en function

JEg har hentet en MailValidator
http://activedeveloper.dk/download/default.asp?mode=showdownload&id=140

Hvordan f.. kalder jeg den, så henter input fra mit formfelt
Avatar billede a1a1 Novice
09. april 2002 - 13:17 #1
kan du ikke lige paste funktionen ind
Avatar billede nogetfx Nybegynder
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&#338; 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&#338; 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&#338; 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
%>
Avatar billede nogetfx Nybegynder
09. april 2002 - 13:22 #3
Det er står også noget i toppen, men da jeg heller ikke lige fatter det.
Men jeg vil tror at det er nemt nok at gå til..
Avatar billede a1a1 Novice
09. april 2002 - 13:35 #4
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

sådan kalder du funktionen

V_Exclude = Array("jc@pc.dk")
inde i funktionen er de email adresse du ikke kan lide (ikke vil sende til)
Avatar billede a1a1 Novice
09. april 2002 - 13:35 #5
det var et svar
Avatar billede nogetfx Nybegynder
09. april 2002 - 13:40 #6
Nej, det bliver ved med at sige skrive at der mangler et @, eller det vil sige at den fatter ikke at det er en variabel...
Avatar billede cape Nybegynder
09. april 2002 - 13:47 #7
så vidt jeg ved så har A1 ret.

Hvad mener du med 'at den fatter ikke at det er en variabel...'
Avatar billede nogetfx Nybegynder
09. april 2002 - 13:50 #8
Den email jeg skrev var: lars@nogetfx.dk
Og siden at den kan skrive at der mangler et @, så må den vel opfatte variablen FrmMail som en email-add
Avatar billede a1a1 Novice
09. april 2002 - 15:02 #9
din form skal hedde:
mailadd

gør den det
Avatar billede nogetfx Nybegynder
09. april 2002 - 15:09 #10
Jep...
Avatar billede a1a1 Novice
09. april 2002 - 15:22 #11
så er det vel funktionen der er underlig....:)
Avatar billede nogetfx Nybegynder
10. april 2002 - 11:43 #12
Fandt ud af at der ikke skulle være "

FrmMail = Request.Form("mailadd")
If ValidateEmail(FrmMail) Then


Men du får lidt for forsøget
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester