Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi
I'm building a Asp.Net website and I need to validate a textboxcontrol. The users input should be a valid email address, how can I do this?

thx
Posted
Comments
NixonUposseen 29-Mar-17 7:55am    
1. Check the user's input on the client side, use email type input.
2. Check that value (email's format, domain's name, server and email's existence) on server side (use this C# code to validate email).
3. Optionally send validation email (use this C# code to send email) which will contain a validation link that a user must visit.

You can just use the validationControls
- The RequiredFieldValidator Control
- The CompareValidator Control
- The RangeValidator Control
- The RegularExpressionValidator Control

In your case you can use the RegularExpressionValidator control.

Here is a link on how to do that:
RegularExpressionValidation control

hope it helped.
 
Share this answer
 
hi this may help you
ASP.NET
  <asp:textbox id="txt_email" runat="server" xmlns:asp="#unknown"></asp:textbox>

<asp:regularexpressionvalidator cssclass="errmsg" id="regexEmailValid" runat="server" validationexpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" >
ControlToValidate="txt_email" ErrorMessage="Invalid Email Format"></asp:regularexpressionvalidator>





Happy coding :)
 
Share this answer
 
v2
Comments
ridoy 5-Sep-13 8:32am    
good response,+4.
 
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