Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a form in Visual Studio 2008 in c# file.
In that form I have a text box for the field e-mail ID.

I want that text box to show some default site ID like @yahoo.com, @gmail.com, @rediffmail.com etc. when entering the e-mail ID of the person.

For example my e-mail ID is [deleted]@gmail.com and if I am entering my e-mail ID [delete]@ after entering the @ symbol the default mail ID should be shown and the text field should not allow the data to be stored unless the @ symbol is mentioned in the text field.


[edit]DON'T SHOUT! It is considered rude - converted to normal case. Don't post your email to any forum, unless you really like spam. General tidy and spelling. Tags. OriginalGriff[/edit]
Posted
Updated 18-Aug-10 22:13pm
v3

Dear Selva,

The following is very useful for you.

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (textBox1.Text.IndexOf("@") > 0)
{
listBox1.Visible = true;
if (textBox1.Text.IndexOf("@") != textBox1.Text.Length)
{
string searchTxt = textBox1.Text.Substring(textBox1.Text.IndexOf("@"));
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (listBox1.Items[i].ToString().Contains(searchTxt))
{
listBox1.SelectedIndex = i;
break;
}
}
}
}
else
{
listBox1.Visible = false;
}
}



Regards,
Hariharan
 
Share this answer
 
v2
Comments
Dalek Dave 19-Aug-10 4:08am    
Minor Edit for Code Block.
Hi Selva

In the textbox leave or validating event you can check..

whether
textbox.text.Indexof("@");
or use regex like
regex rex = new regex(".*@.*");


use regex property match which returns a bool to verify whether the text as an instance of '@' or not..

And depending on the result you can display an error message or whatever.

Hope this gives you an idea..
 
Share this answer
 
v3
User Input Validation in Windows Forms

You can use the text changed event (I think that's what it's called) to check if the @ was entered.

That assumes you are not working with ASP.Net.
 
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