0

In window textbox, I'd like to just allow decimal only.

For example, 8.56

How to?

soclose
  • 2,773
  • 12
  • 51
  • 60
  • 1
    possible duplicate of [How do I make a textbox that only accepts numbers?](http://stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers) – Heinzi Apr 29 '11 at 08:35
  • Check this [link](http://stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers) which may help you. – Deminem Apr 29 '11 at 08:34

2 Answers2

0
Private Sub TextBox1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If IsNumeric(e.KeyChar) Then
    e.Handled = True
End If

End Sub

Jay
  • 3,012
  • 14
  • 48
  • 99
0

You can also do using double.TryParse.

You can check your input on submit button as below mentioned ways.

            double m = 0;

            if (double.TryParse(TextBox1.Text, out m) == false)
            {
                MessageBox.Show("Please enter valid Price");
                TextBox1.Focus();
            }
            else
            {
                // Put your code here
            }
Pankaj Agarwal
  • 11,191
  • 12
  • 43
  • 59