27 November 2006
Quick ASP.NET form email validation
Posted by Mikhail Esteves under: C#; Tips .
A combination of a RequiredFieldValidator and a RegularExpressionValidator to validate email addresses on forms:
<asp :TextBox ID="txtEmail" RunAt="Server" />
<asp :RequiredFieldValidator
ID="reqEmail"
RunAt="server"
ControlToValidate="txtEmail"
ErrorMessage="Email Address required" />
<asp :RegularExpressionValidator
ID="reqAuthEmail"
RunAt="server"
ControlToValidate="txtEmail"
ValidationExpression="^[\w-\.]+@([\w-]+\.)+[\w-]{2,3}$"
ErrorMessage="Valid Email Address required" />
5 Comments so far...
Spencer Says:
28 November 2006 at 5:48 am.
How would you install this and use it? Do you have to have ASP for it? Could you tell me what I would need to use this code for my site? Thanks!
Tim Says:
11 December 2006 at 10:36 am.
The code for the regularexpressionvalidator was exactly what I was looking for. Thanks.
nag Says:
16 August 2007 at 6:39 am.
Thank you very much for this code