我目前正在嘗試驗證文本框,因此只能使用TryParseExact輸入字母(a-Z)。對WindowsForms使用TryParseExact文本框
我有一個檢查時間的代碼,雖然有人可以證明這隻能用字母來完成。
我的代碼如下:
private void textBox2_Validating(object sender, CancelEventArgs e)
{
DateTime dateEntered;
if (DateTime.TryParseExact(textBox2.Text, "HH:mm", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dateEntered))
{
}
else
{
MessageBox.Show("You need to enter valid 24 hour time");
}
}
你是什麼意思'只有字母'?沒有號碼?沒有空格或標點符號? –
@ agent-j這是正確的 – Dan