Imports System.Text.RegularExpressions
Public Class Application
Public Shared Sub Main()
Dim emailAddresses() As String = { "david.jones@a.com", "d.j@server1.a.com", _
"jones@ms1.a.com", "j.@server1.a.com", _
"j@a.com9" }
For Each emailAddress As String In emailAddresses
If RegexUtilities.IsValidEmail(emailAddress) Then
Console.WriteLine("Valid: {0}", emailAddress)
Else
Console.WriteLine("Invalid: {0}", emailAddress)
End If
Next
End Sub
End Class
Module RegexUtilities
Function IsValidEmail(strIn As String) As Boolean
Return Regex.IsMatch(strIn, "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$")
End Function
End Module
|