Regular expression for email address

  • Thread starter Thread starter Mark B
  • Start date Start date
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.
 
Try this one, Mark :

[@]




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
Didn't work.


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

[@]




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
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.
 
re:
!> Didn't work.

It does work.
Check your implementation.



Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
Mark B said:
Didn't work.


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

[@]




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
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.
 
Why not use the regular expression for email addresses that is provided with
the validator?
 
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);
 
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.





Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
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




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================

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);
 
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...




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
re:
!> Thanks all. Just tested:
!> ^.*@.*$
!> for Chinese etc and it works great.

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




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
Mark B said:
Thanks all. Just tested:

^.*@.*$

for Chinese etc and it works great.
 
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>




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
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...




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
Back
Top