2 回答

TA貢獻1854條經(jīng)驗 獲得超8個贊
您可以使用它來驗證輸入框中輸入的數(shù)據(jù)。
public bool IsAccepted(String textToValidate)
{
Regex strPattern = new Regex("^[a-hA-H]*$");
if (!strPattern.IsMatch(textToValidate))
{
return false;
}
return true;
}
這是我如何通過控制臺應(yīng)用程序測試它的屏幕截圖:

TA貢獻1906條經(jīng)驗 獲得超10個贊
try
{
if (this.TxtCoach.Text.Contains('A') ||
this.TxtCoach.Text.Contains('B') ||
this.TxtCoach.Text.Contains('C') ||
this.TxtCoach.Text.Contains('D') ||
this.TxtCoach.Text.Contains('E') ||
this.TxtCoach.Text.Contains('F') ||
this.TxtCoach.Text.Contains('G') ||
this.TxtCoach.Text.Contains('H'))
{
LstFinalB.Items.Add(TxtCoach.Text);
}
else
{
throw new ArgumentException("Correct your coach is valid!");
}
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message);
}
您的 If 語句邏輯錯誤,您將永遠不會有正確的輸入,并且 Listbox.Items.Add(Item) 也在錯誤的位置。
- 2 回答
- 0 關(guān)注
- 126 瀏覽
添加回答
舉報