如何验证.net windows表单应用程序中的文本框 [英] how to validate the text box in .net windows form application
本文介绍了如何验证.net windows表单应用程序中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为我想验证我的文本框。我希望我的文本框不应该在表单提交时为空。它必须取一些值作为输入而不是空格。
i使用它:
if(textbox.text ==)
{
errorProvider1.show(文本框,请输入你的名字);
}
这将占用空白作为输入,这不是我的要求。
请帮帮我..
as i want to validate my textbox. i want that my text box should not be empty at the form submit ion. it must take some value as input but not whitespace.
i have use this:
if(textbox.text=="")
{
errorProvider1.show(textbox,"plese enter your name");
}
this will take white space as input which is not my requirement .
please help me..
推荐答案
使用修剪 [ ^ ]
use Trim[^]
if (textbox.Text.Trim() == "")
{
errorProvider1.show(textbox, "plese enter your name");
}
试试这个:
Try this:
if (textBox1.Text.Trim()==string.Empty)
{
errorProvider1.show(textbox,"plese enter your name");
}
使用 String.IsNullOrWhiteSpace(textbox.Text)
use String.IsNullOrWhiteSpace(textbox.Text)
if (String.IsNullOrWhiteSpace(textbox.Text))
{
errorProvider1.show(textbox, "plese enter your name");
}
这篇关于如何验证.net windows表单应用程序中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文