我写了这个正则表达式函数
Public Function ValidateEmailAddress(ByVal txtEmailAddress As String) As Boolean
Dim pattern As String
pattern = "^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$"
If Regex.IsMatch(txtEmailAddress, pattern) Then
Return True
Else
Return False
End If
End Function
并在子过程中调用该函数:
If ValidateEmailAddress(txtEmailAddress.Text) = True Then
Else
MessageBox.Show("Email Not Valid")
End If
Sub Procedure
当我输入电子邮件时,无论是否正确,我都会收到相同的消息,即电子邮件无效,除了在 If 语句之后单步执行代码时,它会忽略返回 true。请任何人都可以发现这里的问题吗?