Decimal Dots validation on VB textbox

后端 未结 1 621
悲哀的现实
悲哀的现实 2021-01-29 00:29

Under keypress event, I have a function validating the entered characters, this is my code.

Public Function vNum2(val As Object)

    Dim result As Boolean = Fal         


        
相关标签:
1条回答
  • 2021-01-29 01:06

    Try this :

    Public Function vNum2(val As Object)
            Dim result As Boolean = False
            Try
                'Dim allowedChars As String = "42.2.3"
                Dim allowedChars As String = val.ToString()
                'Bellow line will count how many dots are in string, if there one or none, result will be True
                If allowedChars.Where(Function(dots) dots = ".").Count < 2 Then result = True
            Catch ex As Exception
                MsgBox("Error 1010xVNum2: " & ex.Message)
            End Try
            Return result
        End Function
    
    0 讨论(0)
提交回复
热议问题