Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Regular Expression to validate input/email


Message #1 by irfan.syed@g... on Thu, 20 Mar 2003 11:39:41 +0800
I am new to Regular Expression. Does anyone know what expression can I 
use
in Regular Expression Validator to validate that a user has not only
entered some value in a text box but also a valid email address? I am
using the following expression but it only validates when user has 
entered
something. If text box is empty, it won't work.

^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$

Thanks for help.
Message #2 by "Aaron Seet" <aspfriends@i...> on Thu, 20 Mar 2003 21:54:01 +0800
On top of RegularExpressionValidator, you need RequiredFieldValidator to
complete the checking

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>
<asp:TextBox id="txtEmail" runat="server" columns="30"/>

<asp:RequiredFieldValidator runat="server"
ControlToValidate="txtEmail"
Text="No mail server will accept blank address."
Display="dynamic"/>

<asp:RegularExpressionValidator runat="server"
ControlToValidate="txtEmail"
Text="Invalid email address format."
ValidationExpression="^[\w\-\.']+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*?\.[a-zA-
Z]{2,4}$"
Display="dynamic"/>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>


My regexp is not the perfect one - doesn't take into account the 64 char
limit for each dotted block in DNS hostname.


Aaron Seet
http://icelava.net/images/uf980715.gif

----- Original Message -----
From: <irfan.syed@g...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, March 20, 2003 11:39
Subject: [aspx] Regular Expression to validate input/email


I am new to Regular Expression. Does anyone know what expression can I use
in Regular Expression Validator to validate that a user has not only
entered some value in a text box but also a valid email address? I am
using the following expression but it only validates when user has entered
something. If text box is empty, it won't work.

^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$

Message #3 by "Jonathan Larouche" <jlarouche@d...> on Thu, 20 Mar 2003 15:06:44
Here is the regular expression for email adress as documented in RFC by 
W3C (Same validation as any mail server) Email with domain and with ip 
adresses

^(([^<>;()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((([a-z]([-a-z0-9]
*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))
\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-z0-
9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))
\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$

I know it big, but it validate every valid email without exceptions

Regards

Jonathan


> I am new to Regular Expression. Does anyone know what expression can I 
use
in Regular Expression Validator to validate that a user has not only
entered some value in a text box but also a valid email address? I am
using the following expression but it only validates when user has 
entered
something. If text box is empty, it won't work.

^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$

Thanks for help.
Message #4 by irfan.syed@g... on Fri, 21 Mar 2003 10:59:16 +0800
Thank you all for your feedback. I have found another way to validate 
both
empty text box and valid email with only one Regular Expression 
validator
using Button.OnCllick

 Dim r As New System.Text.RegularExpressions.Regex("@")
        If r.IsMatch(txtEmail.Text) =3D True Then
	' Do whatever wanna do. Also at this stage, Regular Expression
validator will fire in.

It is not a great solution, but it works for me!

Thanks Aaron, Jonathon and Josh.


-----Original Message-----
From: Jonathan Larouche [mailto:jlarouche@d...]
Sent: Thursday, March 20, 2003 11:07 PM
To: ASP.NET
Subject: [aspx] Re: Regular Expression to validate input/email



Here is the regular expression for email adress as documented in RFC by
W3C (Same validation as any mail server) Email with domain and with ip
adresses

^(([^<>;()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((([a-z]([-a-z0-
9
]
*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))

\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-z
0
-
9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))
)
)
\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$

I know it big, but it validate every valid email without exceptions

Regards

Jonathan


> I am new to Regular Expression. Does anyone know what expression can I 

> =3D
use
in Regular Expression Validator to validate that a user has not only
entered some value in a text box but also a valid email address? I am
using the following expression but it only validates when user has =3D
entered something. If text box is empty, it won't work.

^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$

Thanks for help.
Message #5 by emullin@a... on Fri, 21 Mar 2003 20:19:24
Hey, I tried to use this expression, but I guess I did it wrong since the 
parser gacked on it.  Does anyone have an example of it loaded into a 
string?

for example :

<asp:RegularExpressionValidator runat="server" 
ControlToValidate="txtEmail" Text="Invalid email address format." 
		ValidationExpression="^[\w\-\.']+@[a-zA-Z0-9\-]+(\.[a-zA-
Z0-9\-]+)*?\.[a-zA-Z]{2,4}$"
		Display="dynamic" />
	
Many Thanks,

Ed Mullin
www.artifactsoftware.com
Writing Better, Faster, Stronger Software

> 
H> ere is the regular expression for email adress as documented in RFC by 
W> 3C (Same validation as any mail server) Email with domain and with ip 
a> dresses

> ^(([^<>;()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((([a-z]([-a-z0-
9]
*> [a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))
\> .){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-
z0-
9> ]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-
5]))))
\> .){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$

> I know it big, but it validate every valid email without exceptions

> Regards

> Jonathan

> 
>>  I am new to Regular Expression. Does anyone know what expression can I 

u> se
i> n Regular Expression Validator to validate that a user has not only
e> ntered some value in a text box but also a valid email address? I am
u> sing the following expression but it only validates when user has 
e> ntered
s> omething. If text box is empty, it won't work.

> ^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$

> Thanks for help.
Message #6 by irfan.syed@g... on Sat, 22 Mar 2003 10:09:52 +0800
This is how it appears in my code and works perfect.

<asp:RegularExpressionValidator id=3D"EmailError" runat=3D"server"
Width=3D"208px" ControlToValidate=3D"txtEmail"
ValidationExpression=3D"^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$"
></
asp:RegularExpressionValidator>

-----Original Message-----
From: emullin@a... [mailto:emullin@a...] 

Sent: Saturday, March 22, 2003 4:19 AM
To: ASP.NET
Subject: [aspx] Re: Regular Expression to validate input/email


Hey, I tried to use this expression, but I guess I did it wrong since 
the
parser gacked on it.  Does anyone have an example of it loaded into a
string?

for example :

<asp:RegularExpressionValidator runat=3D"server"
ControlToValidate=3D"txtEmail" Text=3D"Invalid email address format."
		ValidationExpression=3D"^[\w\-\.']+@[a-zA-Z0-9\-]+(\.[a-zA-
Z0-9\-]+)*?\.[a-zA-Z]{2,4}$"
		Display=3D"dynamic" />
=09
Many Thanks,

Ed Mullin
www.artifactsoftware.com
Writing Better, Faster, Stronger Software

>
H> ere is the regular expression for email adress as documented in RFC
H> by
W> 3C (Same validation as any mail server) Email with domain and with ip
a> dresses

>
^(([^<>;()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((([a-z]([-a-z0-

9]
*>
[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))
\> 
.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-
z0-
9> ]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-
5]))))
\> .){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$

> I know it big, but it validate every valid email without exceptions

> Regards

> Jonathan

>
>>  I am new to Regular Expression. Does anyone know what expression can 
I

=3D
u> se
i> n Regular Expression Validator to validate that a user has not only
e> ntered some value in a text box but also a valid email address? I am
u> sing the following expression but it only validates when user has =3D
e> ntered
s> omething. If text box is empty, it won't work.

> ^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$

> Thanks for help.

  Return to Index