Hi,
I want to validate email in text box through key press event.my code is as follows
Private Sub Textbox5_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox5.Validating
Dim temp As String
temp = TextBox5.Text
Dim conditon As Boolean
emailaddresscheck(temp)
If emailaddresscheck(conditon) = False Then
MessageBox.Show("Enter your email address correctly", "Validation")
TextBox5.Text = ""
End If
End Sub
Private Function emailaddresscheck(ByVal emailaddress As String) As Boolean
Dim pattern As String = "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
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 TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
TextBox5.BackColor = Color.White
Dim temp As String
temp = TextBox5.Text
Dim conditon As Boolean
emailaddresscheck(temp)
If emailaddresscheck(conditon) = True Then
MessageBox.Show("Enter your email address correctly", "Validation")
TextBox5.Text = ""
End If
End Sub
it is not working,pls provide solutions....
I want to validate email in text box through key press event.my code is as follows
Private Sub Textbox5_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox5.Validating
Dim temp As String
temp = TextBox5.Text
Dim conditon As Boolean
emailaddresscheck(temp)
If emailaddresscheck(conditon) = False Then
MessageBox.Show("Enter your email address correctly", "Validation")
TextBox5.Text = ""
End If
End Sub
Private Function emailaddresscheck(ByVal emailaddress As String) As Boolean
Dim pattern As String = "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
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 TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
TextBox5.BackColor = Color.White
Dim temp As String
temp = TextBox5.Text
Dim conditon As Boolean
emailaddresscheck(temp)
If emailaddresscheck(conditon) = True Then
MessageBox.Show("Enter your email address correctly", "Validation")
TextBox5.Text = ""
End If
End Sub
it is not working,pls provide solutions....
Last edited: