• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

How Also to let text accept point .

I have a text box , I want it to accept both numbers and point just to enter amount like this 2.75 .

  Private Sub thiscontrol_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles thiscontrol.KeyPress
        If Char.IsNumber(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
            e.Handled = True
        End If
    End Sub

What also I have to add. ?
0
Ahmadal_najjar2003
Asked:
Ahmadal_najjar2003
  • 2
1 Solution
 
rachitkohliCommented:
Or (e.KeyChar = "." And Split(thiscontrol.Text, ".").Length <= 1)

add this OR condition also, this will make sure only once "." is entered
0
 
rachitkohliCommented:
Private Sub thiscontrol_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles thiscontrol.KeyPress
If Char.IsNumber(e.KeyChar) = True Or (e.KeyChar= "." And Split(thiscontrol.Text, ".").Length <= 1) Then
      e.Handled = True
        End If
    End Sub

this will be a complete event
0
 
Ahmadal_najjar2003Author Commented:
Thanks Alot
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now