【发布时间】:2014-01-18 11:57:16
【问题描述】:
我正在使用 c#.net 2.0 winforms。我在表单中使用 errorprovider 控件来验证文本框。虽然我以编程方式为该文本框赋值。文本框验证方法不会从文本框中获取值或将其视为空白值。如何在文本框中不输入值来验证我的文本框。这是代码
private void textBox6_Validated(object sender, EventArgs e)
{
bTest6 = txtRegExPinIsValid(textBox6.Text);
if (bTest6)
{
this.errorProvider1.SetError(textBox6, "");
}
else
{
this.errorProvider1.SetError(textBox6, "This field must contain Exactly 6 digits");
}
}
private bool txtRegExPinIsValid(string textToValidate)
{
Regex TheRegExpression;
string TheTextToValidate;
string TheRegExTest = @"^\d{6}$";
TheTextToValidate = textToValidate;
TheRegExpression = new Regex(TheRegExTest);
// test text with expression
if (TheRegExpression.IsMatch(TheTextToValidate))
{
return true;
}
else
{
return false;
}
}
在执行更新操作时,我用 ms 访问表中的值填充文本框。如果值正确,请留下它,否则我必须更新它。请帮我。提前致谢
【问题讨论】:
-
如果我手动将光标保留在每个文本框中并执行更新操作一切正常..
标签: winforms validation textbox c#-2.0