Question Validating a email address field

RichyB

Member
Joined
Oct 9, 2009
Messages
6
Programming Experience
Beginner
Hi guys,
Im trying to make a email client, iv got it all working but im looking to validate the email address field to make sure that its actually an email address so it has a @ sign.

Also one other thing is, when the client authenticates with gmail id like to catch the error if its not authenticating properly. Is there a way to do this?

Thanks in advance
 
For validation of the E-Mail I'd suggest Regulare Expression, you'll find ready-to-go patterns here.

GMail is using IMAP, this is nothing more than e text-protocol like POP or FTP...have a look at [ame="http://de.wikipedia.org/wiki/Internet_Message_Access_Protocol"]it[/ame] and it's specifications to figure that out.

Bobby
 
ok what i did was use a error provider. incase anyone looks at this again ill post the code i used

make sure you selected a errorProvider from the tools box and iv named it errProvider
VB.NET:
    Private Sub toBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles toBox.KeyPress
        ' this detects and prompts the user to enter a valid email address
        Dim Expression As New System.Text.RegularExpressions.Regex("\S+@\S+\.\S+")
        If Expression.IsMatch(CType(sender, TextBox).Text) Then
            ErrProvider.SetError(sender, "")
        Else
            ErrProvider.SetError(sender, "Not a valid email.")
        End If
    End Sub
 
What i do, is just do a quick text on the send button

so;

VB.NET:
sub send()
if tobox.text.contains("@") = false hen
msgbox("the to box is not in the correct format")
end if
end sub
etc - doing that for each of the errors you wish to look out for.
 
Haxaro that exactly what i was looking for cheerrs mate, have u gt a way of detecting not authentication, at the min when if i put the wrong gmail username or password in it crashes. Is there a way to catch the error before crashing
 
I think what your not doing is using a try. For things such as emailing, trys are a MUST

VB.NET:
        Try
            Dim client As New SmtpClient(SMTPAddress, Port)
            client.EnableSsl = True
            client.UseDefaultCredentials = False
            client.Credentials = Login
            client.Send(Message)
        Catch ex As SmtpException
            MsgBox("The following error occurred: " & ex.Message)
            SendEmail = "Message Sending Failed!"
            Exit Sub
        End Try

Will now just give you a reason why the email didnt send, but wont crash the entire program.
I have uploaded a sample script that has come straight from my email DLL; and you can view it here (my main website is down): HERE

Hope that helps :)
 
Back
Top