Hi all,
I have different text boxes the I need to validate the user inut. The code that I have (example) does work, the problem is that if there is absolutly nothing in the text box I don't want to get the error message. If I have a starting "0", physically in the text box, or "non-numeric value" then I do want the error message. What happens is when I "clear" everything in the boxes then I get the error also but don't want it if nothing is in the boxes.
Private Sub txtInterestRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInterestRate.TextChanged
Try
If Me.txtInterestRate.Text.Length = 0 Then 'reads interest rate text box
Me.errInput.SetError(Me.txtInterestRate, "Please Enter a valid value") 'if 0 gives error
ElseIf Not IsNumeric(txtInterestRate.Text) Then 'checks input for numeric value
Me.errInput.SetError(Me.txtInterestRate, "Please Enter a valid Numeric value") 'if non-numerics gives error
Throw New Exception("Please enter a valid numeric value")
ElseIf txtInterestRate.Text = 0 Then 'checks input for numeric value
Me.errInput.SetError(Me.txtLoanAmount, "Please Enter a Non Zero valid Numeric value") 'if non-numerics gives error
Throw New Exception("Please enter a valid Non Zero numeric value")
End If
Catch ex As Exception 'exception handeler for error input
MsgBox(ex.Message) 'displays error
Me.txtInterestRate.Text = ("")
End Try
End Sub
Any help would really be appreciated!
Thanks,
Ken