限制TextBox中的输入 [英] Restricting input in TextBox

查看:71
本文介绍了限制TextBox中的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Visual Studio 2008中的C#文件中创建了一个表单.
在该表格中,我有一个用于输入字段电子邮件ID的文本框.

我希望该文本框在输入人员的电子邮件ID时显示一些默认的站点ID,例如@ yahoo.com,@ gmail.com,@ rediffmail.com等.

例如,我的电子邮件ID为[deleted] @ gmail.com,如果我在输入@符号后输入电子邮件ID [delete] @,则应显示默认的邮件ID,并且文本字段不应包含该数据除非在文本字段中提到@符号,否则将被存储.


[edit]不要大喊大叫!它被认为是不礼貌的-转换为正常情况.除非您真的喜欢垃圾邮件,否则请勿将您的电子邮件发布到任何论坛.一般收拾和拼写.标签. OriginalGriff [/edit]

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]

推荐答案

尊敬的塞尔瓦,

以下对您非常有用.

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;
}
}




问候,
Hariharan




Regards,
Hariharan


塞尔瓦

textbox 离开或验证事件中,您可以检查..

是否
Hi Selva

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

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



使用regex property match返回一个布尔值,以验证文本是否为"@"的实例..

根据结果​​,您可以显示错误消息或其他内容.

希望这能给您一个想法.



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..


Windows中的用户输入验证表格

您可以使用文本更改事件(我想这就是它的名字)来检查是否输入了@.

假定您不使用ASP.Net.
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.


这篇关于限制TextBox中的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆