Checking Number Formats in Win Forms

I have several text fields in a win form control that require input confirmation.

How to check the number in the following format

nn.nn

as well as checking that a number is a positive integer

thank

0
source share
1 answer

To check for a valid number, you can use the isnumeric function in the leave event in the text box. If it is not numeric, set focust back to text box 1. Compare the value of int (x) with x to see if it is integer.

If Not IsNumeric(txAngle.Text) Then
  MsgBox("Enter a number between -360 and 360.")
  txAngle.Focus()
else
  x = CDbl(txAngle.Text)
  if int(x) <> x then ' test for integer
  ...
end if
0
source

All Articles