Design a site like this with
Get started

How to make a Textbox that accepts only numbers and one decimal place in Visual Basic?

Create a TextBox and go to its KeyPress Event.

This textbox accepts Numbers, one (1) decimal place and Special keys (Enter, Backspace, Delete, etc.)

Private Sub Textbox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Textbox1.KeyPress

Dim decimalPoint As String
decimalPoint = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator

e.Handled = Not (
                (e.KeyChar = decimalPoint And sender.Text.IndexOf(decimalPoint) = -1) Or
                Char.IsDigit(e.KeyChar) Or
                Asc(e.KeyChar) = 8
End Sub

Published by Christian Foster

Code-blooded, coffee-lover, tall, dark and chubby. I love to draw, has motion-sickness and a sleepy-head. BTW, graduate of BS Computer Science, Associate in Computer Science and certified UiPath RPA Developer. Loyal to my partner and a father of a cute bouncing baby daughter!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: