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.

Object library reference

Function

VBA
Function 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

NameOptional/
Required
Data typeDescription
strEmailRequiredStringThe email address to be validated.

Usage example

VBA
Sub TestIsEmail() Debug.Print IsEmail("test+1@test.com") ' true Debug.Print IsEmail("test+1@testcom") ' false End Sub