Regular expression for email address

M

Mark B

Does anyone know what regular expression I would use for the asp.net regular
expression validator simply to check if there is a @ character entered?

I don't care about any of the other characters because they may be in other
languages such as Chinese, Arabic or Thai.
 
J

Juan T. Llibre

Try this one, Mark :

[@]




===============
Mark B said:
Does anyone know what regular expression I would use for the asp.net regular expression validator simply to check if
there is a @ character entered?
 
M

Mark B

Didn't work.


Juan T. Llibre said:
Try this one, Mark :

[@]




===============
Mark B said:
Does anyone know what regular expression I would use for the asp.net
regular expression validator simply to check if there is a @ character
entered?
I don't care about any of the other characters because they may be in
other languages such as Chinese, Arabic or Thai.
 
J

Juan T. Llibre

re:
!> Didn't work.

It does work.
Check your implementation.



===============
Mark B said:
Didn't work.


Juan T. Llibre said:
Try this one, Mark :

[@]




===============
Mark B said:
Does anyone know what regular expression I would use for the asp.net regular expression validator simply to check if
there is a @ character entered?
I don't care about any of the other characters because they may be in other languages such as Chinese, Arabic or
Thai.
 
S

Scott M.

Why not use the regular expression for email addresses that is provided with
the validator?
 
M

Mark B

Using the asp:RegularExpressionValidator control though:?


<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="TextBox3"
SetFocusOnError="True"
ValidationExpression="[@]">*Enter
valid email
address</asp:RegularExpressionValidator>




Mark Rae said:
Does anyone know what regular expression I would use for the asp.net
regular expression validator simply to check if there is a @ character
entered?

I don't care about any of the other characters because they may be in
other languages such as Chinese, Arabic or Thai.
Try this one, Mark :

[@]
Didn't work.

Works for me:

Regex objRegex = new Regex("[@]");
string strGoodEmail = "12345@7890";
string strBadEmail = "1234567890";
bool blnValidEmail;

blnValidEmail = objRegex.IsMatch(strGoodEmail);
blnValidEmail = objRegex.IsMatch(strBadEmail);
 
J

Juan T. Llibre

re:
!> Why not use the regular expression for email addresses that is provided with the validator?

He stated that the mail addresses might be in
other languages such as Chinese, Arabic or Thai.

Those would fail validation for regular email addresses.

All he is looking for is the presence of @ in a string.
[@] detects that.





===============
 
J

Juan T. Llibre

See:

http://www.iridescence.no/post/RegularExpressionValidatorAndPartialMatches.aspx

Thanks to this blog entry by Fredrik Kalseth we have a valid answer !

The correct expression to use in a RegularExpressionValidator is :


ValidationExpression="^.*@.*$"

---000---

ValidationExpression="@" ...works with the RegEx class, as Mark and I pointed out,
but it doesn't work with the RegularExpressionValidator

"^.*@.*$"

...works with the RegularExpressionValidator




===============

Mark B said:
Using the asp:RegularExpressionValidator control though:?


<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox3" SetFocusOnError="True"
ValidationExpression="[@]">*Enter
valid email address</asp:RegularExpressionValidator>




Mark Rae said:
Mark B said:
Does anyone know what regular expression I would use for the asp.net regular expression validator simply to check
if there is a @ character entered?

I don't care about any of the other characters because they may be in other languages such as Chinese, Arabic or
Thai.
Try this one, Mark :

[@]
Didn't work.

Works for me:

Regex objRegex = new Regex("[@]");
string strGoodEmail = "12345@7890";
string strBadEmail = "1234567890";
bool blnValidEmail;

blnValidEmail = objRegex.IsMatch(strGoodEmail);
blnValidEmail = objRegex.IsMatch(strBadEmail);
 
J

Juan T. Llibre

re:
!> <sigh> Sometimes I wonder just how they get away with it...

Isn't that something ?
Does the phrase "complying with standards" mean anything any more ?

re:
!> Yet another reason for avoiding these validation "training wheels" controls like the plague...

True enough...




===============
 
J

Juan T. Llibre

re:
!> Thanks all. Just tested:
!> ^.*@.*$
!> for Chinese etc and it works great.

I suppose that by "all", you mean "Juan". <g>




===============
Mark B said:
Thanks all. Just tested:

^.*@.*$

for Chinese etc and it works great.
 
M

Mark B

Yes thanks :) Mark also gave some insight with his training wheels comment.

Juan T. Llibre said:
re:
!> Thanks all. Just tested:
!> ^.*@.*$
!> for Chinese etc and it works great.

I suppose that by "all", you mean "Juan". <g>




===============
 
J

Juan T. Llibre

re:
!> Yes thanks :)

:)

re:
!> Mark also gave some insight with his training wheels comment.

Mark is one of the sharpest programming minds here.
He helps a lot of people, too...




===============
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top