嗨,我遇到的问题是我试图验证一个文本框以确保输入了电子邮件地址...我复制了别人的代码,然后将其更改为适合我的程序。但是即使输入了有效的电子邮件仍然是说无效的电子邮件条目
Private Sub EmailTextBox_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles EmailTextBox.Validating
Dim temp As String
temp = EmailTextBox.Text
Dim conditon As Boolean
emailaddresscheck(temp)
If emailaddresscheck(conditon) = False Then
MessageBox.Show("Please enter your email address correctly", "Incorrect Email Entry")
EmailTextBox.Text = ""
EmailTextBox.BackColor = Color.Blue
Else
EmailTextBox.BackColor = Color.Green
End If
End Sub
Private Function emailaddresscheck(ByVal emailaddress As String) As Boolean
Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
Dim emailAddressMatch As Match = Regex.Match(emailaddress, pattern)
If emailAddressMatch.Success Then
emailaddresscheck = True
Else
emailaddresscheck = False
End If
End Function
Private Sub EmailTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmailTextBox.TextChanged
EmailTextBox.BackColor = Color.White
Dim temp As String
temp = EmailTextBox.Text
Dim conditon As Boolean
emailaddresscheck(temp)
: If emailaddresscheck(conditon) = True Then
MessageBox.Show("Please enter your email address correctly", "Incorrect Email Entry")
EmailTextBox.Text = ""
EmailTextBox.BackColor = Color.Yellow
Else
EmailTextBox.BackColor = Color.Green
End If
End Sub
使用的颜色是绿色和黄色,但我更改了框的颜色以识别问题所在.. 框显示为蓝色,因此错误...我假设在这段代码中出现了错误。
Private Function emailaddresscheck(ByVal emailaddress As String) As Boolean
Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
Dim emailAddressMatch As Match = Regex.Match(emailaddress, pattern)
If emailAddressMatch.Success Then
emailaddresscheck = True
Else
emailaddresscheck = False
End If
End Function
在此先感谢.. :) x