When using .NET the pattern ....

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

an encapsulated space will show as invalid but in VB6 it passes as valid but only the part after the space.

So..

dfgdfg [email protected]

is invalid in .net but in VB6 is returns [email protected] as the valid match.

I'm using VBScript_RegExp_55 in VB6.

So the question is if the procedure calling it is incorrect or is there some limitation using 5.5?

Modified procedure from VBF search


Code:
Public Function ValidateRegEx(Optional ByVal Target As Variant, Optional Pattern As String = "", Optional ByVal Item As Long = 0, _
Optional CaseSensitive As Boolean = False, Optional FailOnError As Boolean = True, Optional Persist As Boolean = False) As Boolean
'New email pattern: "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

    Const SUB_NAME = ".ValidateRegEx"
    
    Static oRE      As Object 'VBScript_RegExp_55.RegExp
                              'Static declaration means we don't have to create and compile the RegExp
                              'object every single time the function is called.
    Dim oMatches    As Object 'VBScript_RegExp_55.MatchCollection
    
    On Error GoTo errHandler

    ValidateRegEx = False 'Default return value
    'if FailOnError is false, returns Null on error
    If IsMissing(Target) Then
        'This is the signal to dispose of oRE
        Set oRE = Nothing
        Exit Function
    End If
    'Create the RegExp object if necessary
    If oRE Is Nothing Then
        Set oRE = CreateObject("VBScript.Regexp")
    End If
    With oRE
        'Check whether the current arguments (other than Target)
        'are different from those stored in oRE, and update them
        '(thereby recompiling the regex) only if necessary.
        If CaseSensitive = .IgnoreCase Then
            .IgnoreCase = Not .IgnoreCase
        End If
        .Global = True
        .MultiLine = True
        If Pattern <> .Pattern Then
            .Pattern = Pattern
        End If
        'Finally, execute the match
        If IsNull(Target) Then
            ValidateRegEx = False
        Else
            Set oMatches = oRE.Execute(Target)
            If oMatches.Count > 0 Then
                ValidateRegEx = True
            Else
                ValidateRegEx = False
            End If
        End If
    End With
    'Tidy up and exit
    If Not Persist Then Set oRE = Nothing
    Exit Function

errHandler:
    Set oMatches = Nothing
    Set oRE = Nothing
End Function