如何在文本框中仅允许使用字母和/? [英] How to Allow only Alphabets and / on text box?

查看:73
本文介绍了如何在文本框中仅允许使用字母和/?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须输入一个部门文本,它必须像这样的/AAA/AAA/AAA/AAA/AAA/,它已经像我们输入的文本一样显示了这是__/__/__/__/__

请使用PLS帮助我SIR吗?

I have to Enter in to an Sector text, it has to come like this /AAA/AAA/AAA/AAA/AAA/,ITS ALREADY THE TEXT HAS SET AS WHEN WE HAD ENTERED IN TO THAT TEXT IT WILL SHOWS LIKE THIS __/__/__/__/__

PLS HELP ME SIR?

推荐答案

使用MaskedTextBox

http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx [ ^ ]
use MaskedTextBox

http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx[^]


在TextBox上添加KeyPress事件处理程序.
然后将这段代码放入文本框中.这将只允许使用字母或/.

Add a KeyPress event handler on the TextBox.
Then put in this code into the textbox. This will allow only alphabets or /.

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!Regex.IsMatch(textbox.Text, @"[a-zA-Z/]"))
    {
        e.Handled = true;
    }
}


<pre>Regex rx = new Regex(@"^[a-zA-Z]+


这篇关于如何在文本框中仅允许使用字母和/?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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