【发布时间】:2015-03-12 11:48:26
【问题描述】:
Protected Sub btn_Submit_Click(sender As Object, e As EventArgs) Handles btn_Submit.Click
Dim _lblresponse As Label = Nothing
_lblresponse = New Label
Dim MyEmail As String = txb_Email.Text
If EmailCheck(MyEmail) = True Then
Dim _lblresponse_Valid As Label = Nothing
_lblresponse = New Label
Else
Dim _lblresponse_Invalid As Label = Nothing
_lblresponse = New Label
_lblresponse.Text = "This is not a Valid Email"
Me.plh_Response_Invalid.Controls.Add(_lblresponse)
End If
_lblresponse.Text = "*Your Request Has Been Sent"
Me.plh_Response.Controls.Add(_lblresponse)
Function EmailCheck(ByVal emailAddress As String) As Boolean
Dim pattern As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)
If emailAddressMatch.Success Then
Return True
Else
Return False
End If
End Function
该函数说电子邮件格式是错误的,但是当按下提交按钮时。即使它不是有效的,它也会发送有效的电子邮件。我做错了什么?
【问题讨论】: