hie
how can i restrict the user to enter only numbers in a textbox
babbu
-12
Posting Whiz in Training
Recommended Answers
Jump to PostIs the input fixed at all? You could use a MaskedTextBox and set the mask to a numeric mask. There is also a numeric control you could use:
http://www.codeproject.com/KB/edit/TNumEditBox.aspx
Jump to PostHandle KeyPress Event of TextBox control.
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Not Char.IsDigit(e.KeyChar) Then e.Handled = True End If End Sub
Jump to PostIt depends on the type of numbers you are inputting. If whole numbers, I would suggest using the numericupdown control such as suggested above. Other options such as suggested above will be triggered with each key stroke, just of the textbox's validating event might be better since it would not …
Jump to PostI think this code will allow to enter numbers and decimal points But it will allow ' , " ; etc
i am still looking for another shortcut wayPrivate Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (Char.IsLetter(e.KeyChar) = True) Then e.Handled …
All 13 Replies
sknake
1,622
Senior Poster
Featured Poster
yorro
-6
Junior Poster
kvprajapati
1,826
Posting Genius
Team Colleague
TomW
73
Posting Whiz
Vineeth K
10
Posting Whiz in Training
TomW
73
Posting Whiz
samir_ibrahim
58
Junior Poster
Vineeth K
10
Posting Whiz in Training
raymyster
-13
Light Poster
Dili1234
-2
Junior Poster
khair.ullah
-2
Junior Poster in Training
Icone
-1
Junior Poster in Training
Reverend Jim
commented:
Contributes nothing
+0
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.