私はこの問題を解決しようと多くの時間がかかりましたが、成功することはありませんでした。 私に必要なのはテキストボックスを検証することです:Keypress ISSUE VB.NET
有効チェーン:
10%
0%
1111111.12%
15.2%
10
2.3
無効チェーン:
.%
12.%
.02%
%
123456789123.123
私はKeyPressイベントをサポートし、これらの有効な鎖でテキストボックスを検証する必要があります。
私はしようと試み:
Private Sub prices_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles wholeprice_input_new_item.KeyPress, dozenprice_input_new_item.KeyPress, _
detailprice_input_new_item.KeyPress, costprice_input_new_item.KeyPress
Dim TxtB As TextBox = CType(sender, TextBox)
Dim fullText As String = TxtB.Text & e.KeyChar
Dim rex As Regex = New Regex("^[0-9]{1,9}([\.][0-9]{1,2})?[\%]?$ ")
If (Char.IsDigit(e.KeyChar) Or e.KeyChar.ToString() = "." Or e.KeyChar = CChar(ChrW(Keys.Back))) Then
If (fullText.Trim() <> "") Then
If (rex.IsMatch(fullText) = False And e.KeyChar <> CChar(ChrW(Keys.Back))) Then
e.Handled = True
MessageBox.Show("You are Not Allowed To Enter More then 2 Decimal!!")
End If
End If
Else
e.Handled = True
End If
End Sub
注:正規表現は、任意のパーセント記号と(最大小数点以下2桁、および9の整数)を検証しなければなりません。
助けてください、私はあなたがほとんど正しい答えを持っていたことを考える成功
err、KeyPressで検証し、すべてを返信するのはちょっと奇妙です。 Javascript 'onkeyup'を使って検証し、サーバー側で検証するのはなぜですか**複数のポストバックではなく、文字列全体のみですか? –