So what I am looking to find out, because I'm new to regular expressions, is if it's possible to replace my "Invalid" return statement with a similar statement commented out on the next line, where the character and/or character # of the expression failed at.
Let's use "msteede48@hotmail@.com" as an example input for myEmail variable below...
Option Explicit
Function ValidEmail(myEmail As String) As String
Dim regExp As Object
Set regExp = CreateObject("VBScript.Regexp")
If Len(myEmail) < 6 Then
ValidEmail = ""
Else
With regExp
.Global = True
.IgnoreCase = True
.Pattern = "^(?=[a-z0-9@.!#$%&'*+/=?^_`{|}~-]{6,254}$)(?=[a-z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?=[a-z0-9-]{1,63}$)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"
End With
If regExp.Test(myEmail) = True Then
ValidEmail = "Valid"
Else
ValidEmail = "Invalid"
'ValidEmail = "Error at character:" & CodeToDetermineWhatChar#TheRegexpFailedAtGoesHere & " with a(n):" & CodeToDetermineWhatCharTheRegexpFailedAtGoesHere & "."
End If
End If
Set regExp = Nothing
End Function
Where the output would be something like: Error at character:18 with a(n):@.