how can i limit a user to enter 10 digit no like telephone no in textbox without using regular expressions?????

from 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

I 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

Edited 5 Years Ago by Mitja Bonca: n/a

from 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

ohh thnk u sir,but is there any other way to add validation coz i have tried what u sugggest like:
if textbox1.text.length > 10 then
msgbox "just 10 digit!"

it means when i just enter 11th digit it pops up this message but takes that digit(11) too coz i dont want to change maxlength property.so is there any other way to do that without changing properties..

okey try this :)
If TextBox1.Text.Length > 10 Then
MsgBox("no more 10 !")
TextBox1.Text = Strings.Left(TextBox1.Text, TextBox1.Text.Length - 1)
End If

Edited 5 Years Ago by mustibh: n/a

I 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

thank u very 2 much. i appreciate ur concern.. it worked...u r really my helping hands..

okey try this :)
If TextBox1.Text.Length > 10 Then
MsgBox("no more 10 !")
TextBox1.Text = Strings.Left(TextBox1.Text, TextBox1.Text.Length - 1)
End If

i m really glad as i m getting +ve responses from my frnds all over the world. i really appreciate ur concern sir,it also worked with a lil modification by changing "right" with "left
Thnk u sir and always keep helping...

hi..im ruby
can i ask some favor?
can u help me to solve some program about conversion in number into words?
i need the whole codes for this program and what properties i will used and how to show the output..
please...thank you

Hi ruby,
Please dont post in Someone else thread. And it is already solved. please open other thread.

This question has already been answered. Start a new discussion instead.