Check If String Is Valid Email Address


This code uses VBScript.dll
If you don't have this control, you can download it from

Add Microsoft VBScript Regular Expressions reference to your project (choose Project->References, check the Microsoft VBScript Regular Expressions CheckBox and Press OK).

Now after you added this references, the code can recognize RegExp.
RegExp is type of variable that allow you to check String for certains formats, like if string is Email address, phone number, and your own custom formats.

Form Code

Private Sub Form_Load()
    Dim myReg As RegExp
    Dim email As String
    Set myReg = New RegExp
    myReg.IgnoreCase = True
    myReg.Pattern = "^[\w-\.]+@\w+\.\w+$"
'replace "" with the email address you want to check.
email = ""
    MsgBox "the result of validation checking: " & myReg.Test(email)
End Sub

Go Back