本文介绍了检查在文本框中输入的文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查单击按钮时在文本框中输入的文本. 格式应为以下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控件 [ ^ ] msdn.microsoft/en-us/library/kkx4h3az.aspx [ ^ ] 但是,如果您不使用MaskedTextBox,则可以执行以下操作: www.dotnetperls/regex-match [ ^ ] msdn.microsoft/en-us/library/twcw2f1c.aspx [ ^ ] oreilly/windows/archive/csharp-regular-expressions.html [ ^ ] www.radsoftware.au/articles/regexlearnsyntax.aspx [ ^ ] Better u use MaskedTextBox : Masked C# TextBox Control[^] msdn.microsoft/en-us/library/kkx4h3az.aspx[^] But if u don''t use MaskedTextBox u can do following: www.dotnetperls/regex-match[^] msdn.microsoft/en-us/library/twcw2f1c.aspx[^] oreilly/windows/archive/csharp-regular-expressions.html[^] www.radsoftware.au/articles/regexlearnsyntax.aspx[^]
您可以为此使用MaskedTextBox 您可以在此处找到各种遮罩字符并在MaskedTextBox上提供帮助 msdn.microsoft/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 msdn.microsoft/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
更多推荐
检查在文本框中输入的文本格式
发布评论