• 0
Sign in to follow this  
BrunoVeríssimo

Restringir Teclas No Textbox

Question

Eu tenho um Text, e quero que ele só aceite os numeros 1,2 e 3. Quero que se o usuario apertar qualquer outra tecla, o text não aceite esta tecla....

Ex: eu digito 14253 e apareca apenas 123...

Sei que tem a ver com o evento KeyPress no text, e que tem a ver com o cod Ascii. Mas não to conseguindo restringir as outras teclas....

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Faça assim no evento KeyPress da sua textbox:

    válidos = "123" & Chr(8) 'Backspace

    If InStr(1, válidos, Chr(KeyAscii)) <= 0 Then
        KeyAscii = 0
    End If

Certo? ;)

Graymalkin

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this