テキストボックスに文字のみを入力させます。そうしないと、プロンプトボックスが表示されます。
1.通常の式で実現:
特定の文字列の照合:
例:textBox3コンポーネントの検証メソッドは、大文字のみを入力するように設定されています
private void textBox3_Validating(object sender, CancelEventArgs e)
{
try
{
if (Regex.IsMatch(textBox3.Text, "^[A-Z]+$"))
{
}
else
{
MessageBox.Show("必须是大写字母");
textBox3.Clear();
textBox3.Focus();
}
}
catch (FormatException)
{
MessageBox.Show("必须是大写字母");
textBox3.Clear();
textBox3.Focus();
}
}
2.イベントキープレス
判定
if(! char.IsLetter(e.KeyChar))
{
e.Handled=true;
}
ただやる