A very effective VBA regex function that even accepts plus addressing (plus sign included in the first part of the email before the “at” sign, @, e.g. “test+1@test.com”).
Requires that a reference to the Microsoft VBScript Regular Expressions 5.5 object library is set under Tools > References… in the VBEditor.
The function is case-insensitive and returns true if the email address is valid and false if it’s not.
Table of Contents
Object library reference
Function
VBAFunction IsEmail(strEmail As String) As Boolean Dim regexEmail As New RegExp regexEmail.pattern = "[a-z0-9-.+_]+@[a-z-]+\.[a-z]+" regexEmail.IgnoreCase = True IsEmail = regexEmail.test(strEmail) End Function
Parameters
Name | Optional/ Required | Data type | Description |
strEmail | Required | String | The email address to be validated. |
Usage example
VBASub TestIsEmail() Debug.Print IsEmail("test+1@test.com") ' true Debug.Print IsEmail("test+1@testcom") ' false End Sub