检查在文本框中输入的文本格式 [英] Check format of text entered in textbox
本文介绍了检查在文本框中输入的文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查单击按钮时在文本框中输入的文本.
格式应为以下XXXX-XXXX(2012-2013).
提前thx ....
I want to check text entered in textbox on button click.
The Format Should be like this XXXX-XXXX(2012-2013).
thx in advance ....
推荐答案
最好使用MaskedTextBox:
已屏蔽的C#TextBox控件 [ http://msdn.microsoft.com/en-us/library/kkx4h3az.aspx [ ^ ]
但是,如果您不使用MaskedTextBox,则可以执行以下操作:
http://www.dotnetperls.com/regex-match [ http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx [ ^ ]
http://oreilly.com/windows/archive/csharp-regular-expressions.html [ ^ ]
http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx [ ^ ]
Better u use MaskedTextBox :
Masked C# TextBox Control[^]
http://msdn.microsoft.com/en-us/library/kkx4h3az.aspx[^]
But if u don''t use MaskedTextBox u can do following:
http://www.dotnetperls.com/regex-match[^]
http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx[^]
http://oreilly.com/windows/archive/csharp-regular-expressions.html[^]
http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx[^]
您可以为此使用MaskedTextBox
您可以在此处找到各种遮罩字符并在MaskedTextBox上提供帮助
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx [ ^ ]
另一种选择是检查像这样的正则表达式
You can use MaskedTextBox for this purpose
You can find the various mask characters and help on MaskedTextBox here
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx[^]
Other option is to check with regular expressions like this
Regex.IsMatch(TextBox1.Text,@"[A-Z]{4}\-[A-Z]{4}\(2012\-2013\)")
如果您的问题得到解决,则可以接受该解决方案,否则,请发布您的查询
If your problem is solved, you may accept the solution otherwise please post your queries
这篇关于检查在文本框中输入的文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文