Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Test valid email adresses
Message
De
06/05/2014 17:03:00
 
 
À
06/05/2014 16:21:19
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows NT
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01599639
Message ID:
01599649
Vues:
111
>How do I test to see if email adresses in a table are valid?
>
>what would you recommend as a good regular expression?

Custom code which you can enhance in any way you like:
    Public Function Validate() As Boolean
        Dim lnLocation As Integer = 0

        ' Initialization
        cEmail = Trim(cEmail)

        ' The email cannot be blank
        If cEmail.Length = 0 Then
            cMessage = cEmailCannotBeBlank
            Return False
        End If

        ' No dot
        If InStr(cEmail, ".") = 0 Then
            cMessage = cYouNeedToHaveAtLeastOneDotInTheEmail
            Return False
        End If

        ' No @
        If InStr(cEmail, "@") = 0 Then
            cMessage = cYouNeedToHaveAtLeastOneAtSignInTheEmail
            Return False
        End If

        ' We need to have at least 5 characters
        If cEmail.Length < 5 Then
            cMessage = cYouNeedToHaveAtFiveCharacterInTheEmail
            Return False
        End If

        ' We can't accept an email starting with @
        If Mid(cEmail, 1, 1) = "@" Then
            cMessage = cYouCannotHaveAnEmailStartingWithAnAtSign
            Return False
        End If

        ' The last character cannot be a dot
        If Mid(cEmail, cEmail.Length, 1) = "." Then
            cMessage = cTheLastCharacterOfYourEmailCannotBeADot
            Return False
        End If

        ' If we have more than one @
        If oApp.Occurs(cEmail, "@") > 1 Then
            cMessage = cYouCannotHaveMoreThanOneAtSignInTheEmail
            Return False
        End If

        ' No space
        If InStr(cEmail, " ") > 0 Then
            cMessage = cYouCannotHaveASpaceInTheEmail
            Return False
        End If

        ' No comma
        If InStr(cEmail, ",") > 0 Then
            cMessage = cYouCannotHaveACommaInTheEmail
            Return False
        End If

        ' Bad character
        If oApp.Inlist(UCase(cEmail), "SPAM", "NOSPAM") Then
            cMessage = cTheEmailIsNotValid
            Return False
        End If

        ' After the last dot, we can't have a digit
        If Val(Mid(cEmail, oApp.At(".", cEmail, oApp.Occurs(".", cEmail)) + 1)) > 0 Then
            cMessage = cAfterTheLastDot
            Return False
        End If

        lnLocation = InStr(cEmail, "@")

        ' We cannot have a dot immediately after the @
        If Mid(cEmail, lnLocation + 1, 1) = "." Then
            cMessage = cYouCannotHaveADotAfterAtSign
            Return False
        End If

        lnLocation = InStr(cEmail, ";")

        ' We cannot have a semi-colon
        If lnLocation > 0 Then
            cMessage = cYouCannotHaveASemiColonInTheEmail
            Return False
        End If

        ' We cannot have a dot at the end
        If Mid(cEmail, cEmail.Length, 1) = "." Then
            cMessage = cYouCannotHaveADot
            Return False
        End If

        ' We cannot have a dot before the @
        If oApp.At(".@", cEmail) > 0 Then
            cMessage = cYouCannotHaveADotBeforeAtSign
            Return False
        End If

        Return True
    End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform