lunes, 27 de febrero de 2012
jueves, 23 de febrero de 2012
jueves, 16 de febrero de 2012
Restringir valores permitidos en un textbox
'Solo numeros en un texbox
If InStr(1, "0123456789," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
'Solo letras minusculas sin tildes ni letra 'ñ' en un texbox
If InStr(1, "abcdefghijokmnopqrstuvwxyz," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
'Solo letras mayusculas sin tildes ni letra 'ñ' en un texbox
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
'Solo letras mayusculas y minusculas sin tildes ni letra 'ñ' en un texbox
If InStr(1, "abcdefghijokmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
'Solo letras mayusculas y minusculas con tildes en un texbox
If InStr(1, "abcdefghijokmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóú," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
'Solo letras mayusculas y minusculas con tildes y numeros en un texbox
If InStr(1, "abcdefghijokmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóú0123456789," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
En resumen, habrás notado que simplemente hay que colocar los caracteres que son permitidos. Esta condición tiene que estar dentro del evento KeyPress del Textbox que deseas restringir.
Por ejemplo:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
'Solo numeros en un texbox
If InStr(1, "0123456789," & Chr(8), e.KeyChar) = 0 Then
e.KeyChar = ""
End If
End Sub
Suscribirse a:
Entradas (Atom)