* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.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_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Try
Dim i As Integer = Integer.Parse(SourceControl.Text)
If Me.ErrorProvider1.GetError(SourceControl).Length > 0 Then
Me.ErrorProvider1.SetError(SourceControl, "")
End If
Catch ex As Exception
Me.ErrorProvider1.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/>