Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignoring keystrokes 1

Status
Not open for further replies.

fattyfatpants

Programmer
Apr 22, 2004
68
US
I am wondering how I might go about ignoring certain keystrokes but not others.

Example: I want a user to only enter a 10 digit telephone number without dashes and other non numeric info

I tried coding in the KeyDown event to look for any non numeric info and ignore it

Code:
Private Sub txtPhone_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone.KeyDown
        Select Case e.KeyCode
            Case Keys.D0 To Keys.D9, Keys.Delete, Keys.Back
                'all is good
            Case Else
                'ignore the key like it was never pressed
        End Select
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top