0

があり、とtextBoxの間の正の小数のみを受け入れるようにしたいのですが、どうすればよいですか?0.0020.00

4

4 に答える 4

0

ユーザーが入力するときに小数のみが入力されていることを確認する必要がある場合は、テキスト ボックスの内容をチェックする JavaScript を使用して on key up イベントを適用し、問題のある文字が存在する場合は削除します。

送信時にチェックする必要がある場合は、フォームの送信時に呼び出されるコード内で行います。

于 2013-01-30T11:18:17.880 に答える
0

TextBoxこのようにバリデーターを使用できます

<asp:RangeValidator ID="range" runat="server" 
    ControlToValidate="text1" 
    MinimumValue="0" MaximumValue="20.99" Type="double" />

詳細については、 compareValidatorrangeValidatorregularExpressionValidatorに関するこの記事を確認してください。

幸運を

于 2013-01-30T11:34:06.147 に答える
0

あなたの質問が理解できれば。

   Private Sub TextBox1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso e.KeyChar <> "."c Then
            e.Handled = True
        End If

        'for ne decimal point
        If (e.KeyChar = "."c AndAlso (TextBox1).Text.IndexOf("."c) > -1) Then
            e.Handled = True
        End If
    End Sub

    Private Sub TextBox1_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If Decimal.Parse(TextBox1.Text) >= 0 AndAlso Decimal.Parse(TextBox1.Text) <= 20 Then
            'if positive decimals between 0.00 and 20.00
            'Do stuff
        Else
            'if not positive decimals between 0.00 and 20.00
            e.Cancel = True
        End If
    End Sub
于 2013-01-30T11:55:30.043 に答える
0
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles TextBox1.TextChanged

    Dim myRegex As New Regex("^[0-9]*\.?[0-9]{0,2}$")
    If myRegex.IsMatch(TextBox1.Text.Trim) = False Then
        MsgBox("Invalid characters found")
        Exit Sub
    Else
        If CDec(TextBox1.Text.Trim) < 0 OrElse CDec(TextBox1.Text.Trim) > 20 Then
            MsgBox("Enter value between 0.00 and 20.00")
            Exit Sub
        End If
    End If

    End Sub
于 2013-01-31T07:33:40.870 に答える