views:

21

answers:

1

I have a number of text boxes on a win forms control that need their input validating.

How do I validate for a number in the following format

nn.nn

also, how do I validate that a number is a positive integer

thanks

A: 

To verify a valid number, you can use the isnumeric function in the leave event of the textbox. If it is not numeric, set the focust back to the textbox1. Compare the value of int(x) to x to see if it's an 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
xpda