• 0

Email Validation In Vb


Question

hey guys i need your help in vb

i have a form with a text box and a button

textbox name=textbox5

buttonname=button1

on the click event of the button i wanna check for a valid format of an email address

on writing this code it builds but wont function the way i want it

k = Mid(TextBox5.Text, 1, Len(TextBox5.Text))

z = k Like "[a-zA-Z0-9][@][a-zA-Z0-9][.][a-zA-Z]"

If z = False Then

MsgBox("invalid email")

End If

ive even tried this validation for the 2nd line

z = k Like "[a-zA-Z0-9]*""[@]{1}""[a-zA-Z0-9]*""[.]{1}"[a-zA-Z]*"

could you please help me out

thanks :D

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0

Your pattern is incorrect.

This one works.

*@*.[a-zA-Z][a-zA-Z][a-zA-Z]

when you put [a-z], it is only for one character. Just outta curiosity, why use the mid to store the textbox string in a variable string? It'll work if you just have it like so...

z = textbox5 Like *@*.[a-zA-Z][a-zA-Z][a-zA-Z]

.

.

.

etc.

as long as the email addy is the only thing in the textbox.

Link to comment
Share on other sites

  • 0
Your pattern is incorrect.

This one works.

*@*.[a-zA-Z][a-zA-Z][a-zA-Z]

when you put [a-z], it is only for one character. Just outta curiosity, why use the mid to store the textbox string in a variable string? It'll work if you just have it like so...

z = textbox5 Like *@*.[a-zA-Z][a-zA-Z][a-zA-Z]

.

.

.

etc.

as long as the email addy is the only thing in the textbox.

good point bout the mid..thanx for the syntax

Link to comment
Share on other sites

  • 0

This seems to work

   Dim IsEmailValid As Boolean
    
    IsEmailValid = txtEmailAddress.Text Like "*@*.[a-zA-Z][a-zA-Z][a-zA-Z]"

    If Not IsEmailValid Then
         MsgBox ("invalid email")
    End If
    

Link to comment
Share on other sites

  • 0

it should be checking for the last instance of the . then to see if its at least two chars long. then see if the chars are valid.

there are a few chars that cannot be in an email address.

its more then single line test.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.