Note that there are some explanatory texts on larger screens.

plurals
  1. POTextbox Email Validation
    text
    copied!<p>Hi the problem im having is that im trying to validate a text box to make sure an email address was entered... I copied someone elses code and then changed it to suit my program.. however even when a valid email is entered is still says invalid email entry</p> <pre><code>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 </code></pre> <p>The colours used were green and yellow but I changed the colours of the boxes to identify were the problem was.. the box appears blue so the error ...im assuming is somwere in this snipit of code.</p> <pre><code>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 </code></pre> <p>Thanks in advance.. :) x</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload