Results 1 to 16 of 16

Thread: [2008] How do i limit my textbox to accept only perticular characters.

  1. #1

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    Question [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..

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] How do i limit my textbox to accept only perticular characters.

    heres how to write custom textboxes

  3. #3

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    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.

  4. #4
    Lively Member ComITSolutions's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    94

    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.
    Encourage the fellow member’s efforts by rating

    - ComIT Solutions

  5. #5

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    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...

  6. #6
    Lively Member ComITSolutions's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    94

    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
    Encourage the fellow member’s efforts by rating

    - ComIT Solutions

  7. #7

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    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.

  8. #8
    Lively Member ComITSolutions's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    94

    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
    Encourage the fellow member’s efforts by rating

    - ComIT Solutions

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  10. #10

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    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 ?
    Last edited by SwapsRulez; Mar 4th, 2008 at 11:58 PM.

  11. #11
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  12. #12
    Lively Member ComITSolutions's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    94

    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.
    Encourage the fellow member’s efforts by rating

    - ComIT Solutions

  13. #13

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    Re: [2008] How do i limit my textbox to accept only perticular characters.

    vb Code:
    1. Private Sub Phone_Text_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Phone_Text.MouseClick
    2.         Phone_Text.SelectionStart = 1
    3.     End Sub

  14. #14
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  15. #15

    Thread Starter
    Member SwapsRulez's Avatar
    Join Date
    Nov 2007
    Posts
    55

    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.

  16. #16
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2008] How do i limit my textbox to accept only perticular characters.

    Its working well for me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width