我使用的是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