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!

Mikhail Esteves Says:

30 November 2006 at 12:43 am.

@Spencer: You can use this on any ASP.NET form.

Tim Says:

11 December 2006 at 10:36 am.

The code for the regularexpressionvalidator was exactly what I was looking for. Thanks.

Ahtisam Says:

3 August 2007 at 2:15 pm.

Thanks Man this realy good ..

nag Says:

16 August 2007 at 6:39 am.

Thank you very much for this code

Leave a Reply

Browse

Photography

Projects

Pages

Calendar

November 2006
M T W T F S S
« Oct   Dec »
 12345
6789101112
13141516171819
20212223242526
27282930  

Categories

www.flickr.com