[2008] How do i limit my textbox to accept only perticular characters.
[2008] How do i limit my textbox to accept only perticular characters.
means suppose i want the email textbox, then i'll accept only keys having
a-z,A-Z,_,0-9 only.
for phone number, i'll accept 0-9,- only.
Thanks in advance.. :D
Re: [2008] How do i limit my textbox to accept only perticular characters.
heres how to write custom textboxes
Re: [2008] How do i limit my textbox to accept only perticular characters.
They are the controls. i want it done through the codes. like in VB6. thanks sooo much.... waiting for your answer.
Re: [2008] How do i limit my textbox to accept only perticular characters.
Write Proper handling code in KeyPress Event of the Textbox. Where
Parameter "e" contains the details of the key pressed. When an unwanted key is pressed add aline e.handled=True.
Re: [2008] How do i limit my textbox to accept only perticular characters.
Please can u explain in more detail with coding. i'm new here. dont anything about that. please help me... :(
Re: [2008] How do i limit my textbox to accept only perticular characters.
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case e.KeyChar
Case "1","2","3","4","5","6","7","8","9","0"
Case Chr(keys.Back) '<----- to allow BackSpace
Case Else
e.Handled=True
End Select
End Sub
Re: [2008] How do i limit my textbox to accept only perticular characters.
Thanks so much working.... but i have one problem also...
i have a Masked textbox in the project. when i click on that masked textbox. the cursor location goes to only the position. but i want it to be at the starting position just like the normal textbox.
please help me. i want to complete the project in 15 minutes itself.
i've to go to college at sharp 11 AM in india. :P
thanks in advance. waiting for your reply.
Re: [2008] How do i limit my textbox to accept only perticular characters.
If I have understood ur question. the following code is sufficient
Code:
Private Sub MaskedTextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MaskedTextBox1.MouseClick
MaskedTextBox1.SelectionStart = 1
End Sub
Re: [2008] How do i limit my textbox to accept only perticular characters.
Have a try this one
Code:
Private Sub MaskedTextBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.Enter
MaskedTextBox1.SelectionStart = 0
End Sub
Re: [2008] How do i limit my textbox to accept only perticular characters.
None are working :(
also you are doing right. also the your answers were right.
but still its sticking with the same position. :( donno why ?
Re: [2008] How do i limit my textbox to accept only perticular characters.
This worked for me
Code:
Private Sub MaskedTextBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MaskedTextBox1.MouseClick
MaskedTextBox1.SelectionStart = 0
End Sub
Re: [2008] How do i limit my textbox to accept only perticular characters.
What is Not Working! Post the Code so that we can have a look and suggest u.
Re: [2008] How do i limit my textbox to accept only perticular characters.
vb Code:
Private Sub Phone_Text_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Phone_Text.MouseClick
Phone_Text.SelectionStart = 1
End Sub
Re: [2008] How do i limit my textbox to accept only perticular characters.
That should be 0 instead of 1
Code:
Phone_Text.SelectionStart = 0
Re: [2008] How do i limit my textbox to accept only perticular characters.
Also not working for 0. i've tried enter event also. :(
please help me.
Re: [2008] How do i limit my textbox to accept only perticular characters.