string1

 

Check If String Is Valid Email Address


Check If String Is Valid Email Address


Preparations

This code uses VBScript.dll
If you don't have this control, you can download it from
www.microsoft.com/msdownload/vbscript/scripting.asp

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 "myemail@hotmail.com" with the email address you want to check.
email = "myemail@hotmail.com"
MsgBox "the result of validation checking: " & myReg.Test(email)
End Sub