Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to validate email address using Regex in c#,Asp.Net?

For Ex? xyz@gmail.88 or xyz@gmail.c4

How to solve above example?

Thanks in advance?
Posted

You can use good old Regex:

e.g. pattern: ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$

See:
* Email Address Validation Using Regular Expression[^]
* using-a-regular-expression-to-validate-an-email-address[^]


See also previous answers:
* How Do I Verify Email Address[^]
* How to validate Email Address in Web Form in C#.NET[^]

Cheers,
C
 
Share this answer
 
v3
Comments
24983 15-Sep-14 6:00am    
Thanks ur Reply...But not checking xyz@gmail.88
Need to allowed @gmail.com/uk/net/info etc...
Joezer BH 15-Sep-14 6:06am    
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$
is just an example,
you can modify to support nubers at the end of the domain like this:
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z0-9]{2,4}$

Hi,

you can use ..


XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="regExEmail" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please enter proper EMAIL id" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+
[-.]\w+)*"></asp:RegularExpressionValidator>



you have to select RegularExpressionValidator from validation list..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900