验证两个文本框(C#)

时间:2017-03-11 18:21:17

标签: c# uwp

我有两个文本框,提示用户在每个文本框中输入一个整数。我已经完成了所有代码(代码验证texbox是否为空,如果只输入整数,以及第二个texbox中插入的数字是否大于第一个texbox中输入的数字。 我在这里留下一个简单的代码示例(我已经完成了所有代码):

private async void generate_Click(object sender, RoutedEventArgs e)
{
    if (String.IsNullOrWhiteSpace(min.Text) || String.IsNullOrWhiteSpace(max.Text))
    {
        // I already have the code done ...
        // error message
    }    
    else
    { 
        // I already have the code done ...
        // Here it does the operation with the two numbers entered
    }
}

private async void min_TextChanged(object sender, TextChangedEventArgs e)
{
    if (System.Text.RegularExpressions.Regex.IsMatch(min.Text, "[^0-9]"))
    {
        // I already have the code done ...
        // error message
    }

}

private async void max_TextChanged(object sender, TextChangedEventArgs e)
{
    if (System.Text.RegularExpressions.Regex.IsMatch(max.Text, "[^0-9]"))
    {
        // I already have the code done ...
        // error message
    }
}

我只有一个问题:我在哪里放置代码(我已完成此代码)以验证在第二个文本框中输入的数字是否大于在第一个texbox中输入的数字?这是我的问题。

我只是想知道我把代码放在哪里:

if (maxValue < minValue) 
{ 
     // I already have the code done ... 
     // error message 
}

1 个答案:

答案 0 :(得分:0)

您可以将代码放入&#34;否则&#34; in&#34; generate_Click&#34;当你正在开除你的手术时。或者你可以在两个文本框中的函数textChanged中完成。