VB.Net Tutorial/Regular Expressions/Match Email

Материал из VB Эксперт
Перейти к: навигация, поиск

Match Email

Imports System.Text.RegularExpressions
Public Class Tester
    Public Shared Sub Main
        Dim testString As String
        Dim emailPattern As String = _
           "^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@" & _
           "([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$"
        testString = "a@nowhere.ru"
        Console.WriteLine(testString & Space(3) & _
           Regex.IsMatch(testString, emailPattern))
        testString = "a@doe@mybad.ru"
        Console.WriteLine(testString & Space(3) & _
           Regex.IsMatch(testString, emailPattern))
    End Sub

End Class
a@nowhere.ru   True
a@doe@mybad.ru   False