如何验证用户在文本框中输入的字符串? [英] How can I validate user entered string in textbox?
本文介绍了如何验证用户在文本框中输入的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何验证文本框中用户输入的字符串?
我的意思是只应使用字母字符,如果有人输入数字或标点符号,则不应在该文本框中接受该字符.
How can I validate user entered string in textbox?
I mean it should be alphabetic characters only, if anybody enter digits or punctuation symbols it should not be accepted in that textbox.
推荐答案
使用 ^ ]并将掩码设置为仅上和下AZ
Use a Masked Text box[^] and set the mask to only upper and lower A-Z
现在C#的Windows应用程序中的文本框具有称为事件的名称
您要做的就是使用文本框的KeyPress事件并粘贴以下代码...
Now TextBox in Windows application of C# have something called as events
all u have to do is use the KeyPress event of the textbox and paste in the following code...
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//only numbers code
if (char.IsNumber(e.KeyChar) == false)
{
e.Handled = true;
}
//backspace workin keycode
if (e.KeyChar == (char)Keys.Back)
{
e.Handled = false;
}
//if u want that alphabets must be entered then just use
// char.IsLower in place of char.IsNumber
}
和你做了...
一旦找到有用的答案,就对我的答案进行评分
谢谢&问候
基数:rose:
and ur done...
Do rate my answer once u find it useful
Thanks & Regards
Radix :rose:
针对此类问题,我创建了一篇文章
只需检查以下链接,您将得到您问题的答案
增强的文本框控件
for this kind of issue i have created a one article
just check below link you will get answer to your question
Enhanced Textbox Control
这篇关于如何验证用户在文本框中输入的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文