Regular Expression to validate Email address

Vishesh's picture
Pass a string as a parameter to the below procedure to check whether the string is a valid email id or not.
Public Function blnEmailValid(ByVal strEmailAdd As String) As Boolean
    With CreateObject("VBScript.RegExp")
        .IgnoreCase = True
        .Global = True
        .Pattern = "^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
        blnEmailValid = .Test(strEmailAdd)
    End With
End Function
 
Sub Test()
    MsgBox blnEmailValid("abc@EE.com")
End Sub