は、私の知る限りでは、それはあなたが必要とするものありませんが、それは本当に不要な表現です。各文字がA〜Z、0〜9または空白であるかどうかを調べるのではなく、のうち、でないものを探します。
Dim pattern As String = "[^A-Z0-9 ]"
Dim r As New Regex(pattern, RegexOptions.IgnoreCase)
If r.IsMatch(TextBoxX1.Text) Then
MessageBox.Show("Invalid input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
注:試合は大文字と小文字を区別しないあるので、私はA-Z
を指定していてもそれは同様a-z
と一致しますRegexOptions.IgnoreCase
を指定します。
オンラインテスト:https://dotnetfiddle.net/Q23XiA
パターンの説明:
[^ => Match any character that IS NOT...
A-Z0-9 => ...A-Z, 0-9 or a space (there's a space on the end of that).
] => End of character group.