how can i limit a user to enter 10 digit no like telephone no in textbox without using regular expressions?????
sidyusuf
0
Light Poster
Recommended Answers
Jump to Postfrom the properties of that textbox change MaxLength=10
or textbox changed event like this:
if textbox1.text.length > 10 then
msgbox "just 10 digit!"
end if
Jump to PostI would rather choose KeyPress event, where you can use "e" parameter and set its Handled property:
Private Sub textBox1_KeyPress(sender As Object, e As KeyPressEventArgs) If textBox1.Text.Length >= 10 Then If e.KeyChar <> ControlChars.Back Then e.Handled = True End If End If End Sub
Jump to PostGo and try my example code!!! It will not take more then 10 characters!!
Thats why we have key events.
Jump to Postokey try this :)
If TextBox1.Text.Length > 10 Then
MsgBox("no more 10 !")
TextBox1.Text = Strings.Left(TextBox1.Text, TextBox1.Text.Length - 1)
End If
All 16 Replies
mustibh
0
Newbie Poster
Mitja Bonca
557
Nearly a Posting Maven
sidyusuf
0
Light Poster
Mitja Bonca
557
Nearly a Posting Maven
mustibh
0
Newbie Poster
sidyusuf
0
Light Poster
sidyusuf
0
Light Poster
mustibh
0
Newbie Poster
easyrubs
-1
Newbie Poster
easyrubs
-1
Newbie Poster
Pgmer
50
Master Poster
Featured Poster
AJN25
0
Newbie Poster
hhhhhhhhhh
0
Newbie Poster
hhhhhhhhhh
0
Newbie Poster
Varney W
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
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.