Maneesh Massey
Member
Hello,
I am working on an application in Excel VBA which is almost complete. Just need to know how to validate email addresses in text box entry on a UserForm.
I googled and found this code from a website.
I would like to validate email addresses on Textbox_Exit Event on the form.
I do not how to use the above code. Where should this code go and how to call it from the Textbox_Exit Event ?
Please help.
Appreciate all help.
Regards,
Maneesh
I am working on an application in Excel VBA which is almost complete. Just need to know how to validate email addresses in text box entry on a UserForm.
I googled and found this code from a website.
I would like to validate email addresses on Textbox_Exit Event on the form.
Code:
Option Explicit
Const MODULE_NAME As String = "modMail"
'' Validate email address
Public Function ValidateEmailAddress(ByVal strEmailAddress As String) As Boolean
On Error GoTo Catch
Dim objRegExp As New RegExp
Dim blnIsValidEmail As Boolean
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
blnIsValidEmail = objRegExp.Test(strEmailAddress)
ValidateEmailAddress = blnIsValidEmail
Exit Function
Catch:
ValidateEmailAddress = False
MsgBox "Module: " & MODULE_NAME & " - ValidateEmailAddress function" & vbCrLf & vbCrLf _
& "Error#: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Function
Please help.
Appreciate all help.
Regards,
Maneesh