* =?Utf-8?B?RG9vZ2xv?= <Do****@discuss ions.microsoft. com> scripsit:
How do I check to see if my textbox has a alpha character in it?
I don't want alpha characters, numeric only.
I would not prevent the user from entering these characters, instead I
would validate input in the textbox's 'Validating' event and make the
user aware of malformed input using an error provider. For example:
\\\
Private Sub TextBox1_Valida ting( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Valida ting
Dim SourceControl As TextBox = DirectCast(send er, TextBox)
Try
Dim i As Integer = Integer.Parse(S ourceControl.Te xt)
If Me.ErrorProvide r1.GetError(Sou rceControl).Len gth > 0 Then
Me.ErrorProvide r1.SetError(Sou rceControl, "")
End If
Catch ex As Exception
Me.ErrorProvide r1.SetError( _
SourceControl, "Value must be an integer." & ex.Message & ")" _
)
End Try
End Sub
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>