Click here to Skip to main content
14,766,280 members
Please Sign up or sign in to vote.
4.11/5 (2 votes)
See more:
I have a normal text box for entering Email ID, but requirement is text box should have "@", ".com" inherently in it while loading the page plz go through this answer me.....
Posted
Comments
midnight_ 24-Jul-13 9:38am
   
I think this has nothing to do with validation. Its rather masking/prefilling a textbox.
The easy way could be two textboxes between the labels "@" and ".com".

=> [ ]@[ ].com

Hi,

You can use a regular expression:
http://msdn.microsoft.com/en-us/library/az24scfc.aspx[^]
http://msdn.microsoft.com/en-us/library/ms228595%28v=vs.110%29.aspx[^]
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^]
Email Address Validation Using Regular Expression[^]
http://stackoverflow.com/a/16168103[^]

Instead of a RegEx to validate an email address, you can also try this:
http://stackoverflow.com/a/16168118[^]

[EDIT]

Just checking whether the given email address contains "@" and ".com" wouldn't be enough to validate an email address: if you just would check for "@" and ".com", then even .com@ would be valid.
   
v2
You don't really need a masked text box. You should just put this code where you want to validate the email.

if (TextBox1.Text.Contains("@")) {
    if (TextBox1.Text.Contains(".com")) {
        MessageBox.Show("Valid Email");
    }
} else {

}
   
v2
Comments
Herman<T>.Instance 24-Jul-13 10:33am
   
Text.ToString.Contains?? That is not c# code!!
Text is already a String value
Contains is not a property of text.,...bad solution! --> Sorry my bad!
[no name] 24-Jul-13 20:10pm
   
contains is a property of .ToString do your research man.
[no name] 25-Jul-13 18:10pm
   
It is? Since when? According to MSDN Contains is a method (not a property) of the String class.
Your code will not compile.
Calling ToString on a string is useless
MsgBox is undefined
[no name] 26-Jul-13 8:12am
   
oops my bad your right .ToString is not needed just .Contains sorry about that .

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