masked textbox?
Hi!
I need to make a textbox only accept numbers! No letters or special symbols!
//H
-Rest in peace leechers-
Your PM box is 100% full.
Code:Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim NumbersAccepted As String = "0123456789" 'or the numbers you want to use If NumbersAccepted.IndexOf(e.KeyChar) = -1 Then e.Handled = True End If
I would, but I prefer smaller projects.
Yeah, that's the only thing that sucks about that method. There's other better ways of doing it, I'll check my project folder (about 100 projects )
I think this may be why you can't backspace:
I'm not sure, but you should probably look at it...Code:If NumbersAccepted.IndexOf(e.KeyChar) = -1 Then e.Handled = True
I have another possible solution, but I don't feel like posting it right now
Just PM me and I will answer it later (I'm too busy unpacking stuff from vacation)
Problem solved //Close
Found a other way that worked much better Thans btw
-Rest in peace leechers-
Your PM box is 100% full.
What was it? I know I have it somewhere, but I've gone through 30 projects in like 2 hours and I don't wanna check the rest -.-
Post the code, I know I have it but I cant find it :@
Sure,
Code:Private Function ValidateNumeric(ByVal strText As String) _ As Boolean ValidateNumeric = CBool(strText = "" _ Or strText = "-" _ Or strText = "-." _ Or strText = "." _ Or IsNumeric(strText)) End FunctionCode:If Not ValidateNumeric(TextBox1.Text) Then code here end if
-Rest in peace leechers-
Your PM box is 100% full.