多个文本框验证及其组合
Multiple textBox validation and their combinations
我的 WPF 中有多个文本框,想检查它们是否根据所需的应用程序逻辑正确填写:
textBox1 - 总是强制填写
textBox2 - 总是强制填写
textBox3 - 如果 !string.IsNullOrEmpty -> textBox4 也必须填写
textBox4 - 如果 !string.IsNullOrEmpty -> textBox3 也必须填写
textBox5 - 如果 !string.IsNullOrEmpty -> textBox6 也必须填写
textBox6 - 如果 !string.IsNullOrEmpty -> textBox5 也必须填写
所以要么填写 texBox3 和 4 -OR- textBox5 和 6 要么全部填写 3 + 4 + 5 +6.
我尝试过使用 if 语句,if 语句使用 ||布尔逻辑等等。我总是被困在一个无法工作的解决方案中。
虽然这是一个直接的开始,但从未在可行的事情上取得进一步进展:
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("Fill out textBox1 and textBox2");
}
提前感谢您的任何建议。
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("Fill out textBox1 and textBox2");
return;
}
// two filled out or two empty
if (string.IsNullOrEmpty(textBox3.Text) != string.IsNullOrEmpty(textBox4.Text))
{
MessageBox.Show("Fill out or empty textBox3 and textBox4");
return;
}
// two filled out or two empty
if (string.IsNullOrEmpty(textBox5.Text) != string.IsNullOrEmpty(textBox6.Text))
{
MessageBox.Show("Fill out or empty textBox5 and textBox6");
return;
}
// if all empty error
if (string.IsNullOrEmpty(textBox3.Text) && string.IsNullOrEmpty(textBox5.Text))
{
MessageBox.Show("Fill out 3,4 or 5,6 or 3,4,5,6");
}
我的 WPF 中有多个文本框,想检查它们是否根据所需的应用程序逻辑正确填写:
textBox1 - 总是强制填写
textBox2 - 总是强制填写
textBox3 - 如果 !string.IsNullOrEmpty -> textBox4 也必须填写
textBox4 - 如果 !string.IsNullOrEmpty -> textBox3 也必须填写
textBox5 - 如果 !string.IsNullOrEmpty -> textBox6 也必须填写
textBox6 - 如果 !string.IsNullOrEmpty -> textBox5 也必须填写
所以要么填写 texBox3 和 4 -OR- textBox5 和 6 要么全部填写 3 + 4 + 5 +6.
我尝试过使用 if 语句,if 语句使用 ||布尔逻辑等等。我总是被困在一个无法工作的解决方案中。
虽然这是一个直接的开始,但从未在可行的事情上取得进一步进展:
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("Fill out textBox1 and textBox2");
}
提前感谢您的任何建议。
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("Fill out textBox1 and textBox2");
return;
}
// two filled out or two empty
if (string.IsNullOrEmpty(textBox3.Text) != string.IsNullOrEmpty(textBox4.Text))
{
MessageBox.Show("Fill out or empty textBox3 and textBox4");
return;
}
// two filled out or two empty
if (string.IsNullOrEmpty(textBox5.Text) != string.IsNullOrEmpty(textBox6.Text))
{
MessageBox.Show("Fill out or empty textBox5 and textBox6");
return;
}
// if all empty error
if (string.IsNullOrEmpty(textBox3.Text) && string.IsNullOrEmpty(textBox5.Text))
{
MessageBox.Show("Fill out 3,4 or 5,6 or 3,4,5,6");
}