+ Reply to Thread
Results 1 to 3 of 3

Validate textbox entry

  1. #1
    Stuart
    Guest

    Validate textbox entry

    I present a textbox where the user knows to enter only text (upper case,
    lower case or a mixture) and/or numbers. Also no spaces.

    I can use trim to remove spaces.....but how to check for just alphabetic
    characters and numbers, please?

    Regards.



  2. #2
    Darrin Henshaw
    Guest

    Re: Validate textbox entry

    Use the KeyDown event. This is some code, I use to allow the users only
    to enter numbers for a zipcode:

    Private Sub ZipCode_KeyDown(ByVal KeyCode As _ MSForms.ReturnString,
    ByVal Shift As String)
    With Me.ZipCode
    Select Case True
    Case (KeyCode >= 95 And KeyCode < 105)
    'exit quietly
    Case (KeyCode >= 48 And KeyCode < 57)
    'exit quietly
    Case KeyCode = 9 'tab
    Case KeyCode = 8 'backspace
    If Len(.Text) > 0 Then
    .Text = Left(.Text, Len(.Text) - 1)
    End If
    KeyCode = 0
    Case Else
    KeyCode = 0
    Beep
    End Select
    End With
    End Sub


    Modify your's like so:

    Private Sub TextBox1_KeyDown(ByVal KeyCode As _ MSForms.ReturnString,
    ByVal Shift As String)
    With Me.ZipCode
    Select Case True
    Case (KeyCode >= 97 And KeyCode < 122)
    'exit quietly
    Case (KeyCode >= 48 And KeyCode < 57)
    'exit quietly
    Case (KeyCode >= 65 And KeyCode < 90)
    'exit quietly
    Case KeyCode = 9 'tab
    Case KeyCode = 8 'backspace
    If Len(.Text) > 0 Then
    .Text = Left(.Text, Len(.Text) - 1)
    End If
    KeyCode = 0
    Case Else
    KeyCode = 0
    Beep
    End Select
    End With
    End Sub

    I might have something wrong, modifying it to fit your needs. But it's
    enough to get started.

    *** Sent via Developersdex http://www.developersdex.com ***

  3. #3
    Darrin Henshaw
    Guest

    Re: Validate textbox entry

    I actually started modifying it for your needs before I started the
    post. So ignore my first piece of code, and only take a look at the
    second part.

    *** Sent via Developersdex http://www.developersdex.com ***

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1