我使用的是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访问表中的值填充文本框。如果这个值是正确的,就放弃它,否则我必须更新它。请帮帮我。在此先感谢
如果我手动保持光标在每一个文本框,并执行更新操作一切正常。 – user3181915