Validating e-mail with regular expression VB.Net

后端 未结 6 1751
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 16:13

I\'m working on a small project in VB.Net where I get a input from a textbox, and need to verify that this is an e-email address.

I found this expression \"^[_a-z0-9

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 16:49

    Email address: RFC 2822 (simplified) Matches a normal email address. Does not check the top-level domain. Requires the "case insensitive" option to be ON.

    Dim FoundMatch As Boolean
    Try
        FoundMatch = Regex.IsMatch(txtEmail.text, "\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)
    Catch ex As ArgumentException
        'Syntax error in the regular expression
    End Try
    
    If Not FoundMatch Then
       Error = True
    Else
       Error = False
    End If
    

提交回复
热议问题