checking the format of e-mail in a textbox

Z

zafar

hi everyone, I have a textbox which contains the e-mail address of
user, but I have no Idea how to apply the regular expression in
VB.net, what would be the solution for the is e-mail given in text box
have proper format (e.g (e-mail address removed)), can anyone tell me the
solution for this, the reply would be appriciated.... thanx
 
R

Rick

Google for "Email Regex", you will get tons of hits.

To really cover all cases of valid email addresses you need a very long
regex which is probably subject to change at any time in the future as more
extensions like "biz" etc are added.

I tried to make a more complete regex to validate an email address before
storing it in a database, but immediately ran into problems with odd
addresses like (e-mail address removed). I ended up going with the most simple
check for at least one letter before and "@" and ends with "." + two
letters. I figured that any invalid email address would be cought by the
SMTP server whenever it is used which is the "final authority" anyway and
will keep current with whatever is considered valid at the time.

HTH

Rick
 
B

Brad Prendergast

hi everyone, I have a textbox which contains the e-mail address of
user, but I have no Idea how to apply the regular expression in
VB.net, what would be the solution for the is e-mail given in text
box have proper format (e.g (e-mail address removed)), can anyone tell me
the solution for this, the reply would be appriciated.... thanx

In the simplest form:
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

should give you what you're looking for...
 
R

Randy

Brad, or any one else
Thank you for posting in the news groups
I'm very new to programing in fact I have only copied the "helo world" stuff
from a book into the IDE thus far.
However I'm following the news groups to learn from other peoples questions

Your solution looks like the same expression three times one before the @
sign one after the @ sign and one after the (DOT sign) except for the extra
+ sign in the first one? "\w+([-+.]\w+)*" can you tell me the meaning of
this? I think "*" is a wild card (at least it was in my DOS days)

Thank you in advance from a true newbe,

Randy

Brad Prendergast said:
hi everyone, I have a textbox which contains the e-mail address of
user, but I have no Idea how to apply the regular expression in
VB.net, what would be the solution for the is e-mail given in text
box have proper format (e.g (e-mail address removed)), can anyone tell me
the solution for this, the reply would be appriciated.... thanx

In the simplest form:
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

should give you what you're looking for...

--
Brad Prendergast
"It has long since come to my attention that people of accomplishment
rarely sat back and let things happen to them. They went out and
happened to things." -- Leonardo da Vinci (1452 - 1519)
 
B

Brad Prendergast

Brad, or any one else
Thank you for posting in the news groups
I'm very new to programing in fact I have only copied the "helo
world" stuff from a book into the IDE thus far.
However I'm following the news groups to learn from other peoples
questions

Your solution looks like the same expression three times one before
the @ sign one after the @ sign and one after the (DOT sign) except
for the extra + sign in the first one? "\w+([-+.]\w+)*" can you tell
me the meaning of this? I think "*" is a wild card (at least it was
in my DOS days)

Thank you in advance from a true newbe,

Randy

Brad Prendergast said:
hi everyone, I have a textbox which contains the e-mail address of
user, but I have no Idea how to apply the regular expression in
VB.net, what would be the solution for the is e-mail given in text
box have proper format (e.g (e-mail address removed)), can anyone tell me
the solution for this, the reply would be appriciated.... thanx

In the simplest form:
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

should give you what you're looking for...

-- Brad Prendergast
"It has long since come to my attention that people of
accomplishment rarely sat back and let things happen to them. They
went out and happened to things." -- Leonardo da Vinci (1452 -
1519)

Take a look at http://msdn2.microsoft.com/en-us/library/az24scfc.aspx
if you jump to the links it might make it a bit easier for you to
understand. What I ended up doing at one point was putting a 'cheat
sheet' together from the pages.
 
Z

zafar

hi everyone, I have a textbox which contains the e-mail address of
user, but I have no Idea how to apply the regular expression in
VB.net, what would be the solution for the is e-mail given in text
box have proper format (e.g (e-mail address removed)), can anyone tell me
the solution for this, the reply would be appriciated.... thanx

In the simplest form:
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

should give you what you're looking for...

--
Brad Prendergast
"It has long since come to my attention that people of accomplishment
rarely sat back and let things happen to them. They went out and
happened to things." -- Leonardo da Vinci (1452 - 1519)


thanx for guiding me..... but would you plz tell me how can I apply
this regular expression in my VB.Net because I have no Idea about
this.... let ii have a from having a textbox in it,,,, user types an e-
mail address in it, and before adding that text to database I want to
check whether the given text follow the e-mail format or not....
i required a code for apply these regular expression to my form... plz
can you guide me for this,,, I will be really thankfull to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top