Solo aceptar números o solo letras en un TextBox – VB.Net 2005
Hola nuevamente, si quieres hacer que el TextBox de un formulario solo acepte letras o solo acepte números, deberias usar el evento KeyPress del TexBox en mencion, de la siguiente manera:
1.- Ir a la parte del código de tu formulario. (Solo dar click derecho a cualquier parte del formulario y elegir View Code)
2.- Elige el nombre de tu TexBox y luego elige el evento KeyPress.
3.- Dentro de la función creada automaticamente por Visual Basic inserta el siguiente codigo según tus requerimientos.
Aceptar Solo Números
Aceptar Solo Letras
Y listo, aquí en modo texto para copiarlo:
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
Categorías: VB.NET
aceptar letras TextBox, aceptar numeros TextBox, TextBox VB.Net
agradecido ;D
me sirvio para un trabajo de la universidad
muy buen aporte gracias
Hola como estas veo que esto es interesante pero como le hago para que solo me acepte puras minusculas me podrias ayudar
Hola Jesus, tu quieres que se conviernta a minusculas todo lo que escriban en un texbox o quieres que tajantemente el usuario tenga que escribir en minusculas?
Al escribir sobre este texto, este cambiara a mayúsculas o minúsculas automáticamente.
Mayúsculas:
TextBox1.Text = UCase(TextBox1.Text)
MinÚsculas:
TextBox1.Text = LCase(TextBox1.Text)
como hacer que el textbox al escribir ingrese mayusculas solamente
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim CadenaTemporal as String
CadenaTemporal = Chr(KeyAscii)
KeyAscii = Asc(UCase(CadenaTemporal))
End Sub
muy bueno me fue de gran ayuda grax
Hola buen dia! EL problema es el siguiente! Como hacer que un textbox solo acepte letras y espacios! Ejemplo; «José Manuel» ah por cierto que ecepte acentos.
Actualmente tengo lo siguiente:
private void txbApMat_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 65 && e.KeyChar = 97 && e.KeyChar <= 122) || e.KeyChar == 8 || e.KeyChar == 'ñ' || e.KeyChar == 'Ñ')
{
e.Handled = false;
}
else
{
this.errorProvider1.SetError(txbApMat, "Favor de capturar su Apellido Materno con letras");
e.Handled = true;
}
}
Si valida que sean solo letras pero pss no me deja poner espacios ni acentos!
Hola buen dia! Para que puedsas hacer que un textbox solo acepte letras y espacios! Ejemplo; “José Manuel” ah por cierto que ecepte acentos.
Actualmente tengo lo siguiente:
Private Sub txtNombres_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNombres.TextChanged
txtNombres.Text = StrConv(txtNombres.Text, vbProperCase) ‘ convierte la primera letra a mayuscula
txtNombres.SelectionStart = Len(txtNombres.Text)
txtNombres.Text = LTrim(Replace(txtNombres.Text, ” “, ” “)) ‘no acepta espacios en blanco al inicio y solo un espacio entre palabras
txtNombres.SelectionStart = Len(txtNombres.Text)
End Sub
Gran Aporte…me funciono a la perfección GRACIAS.
Como le hago para que me acepte numeros y letras??? Quiero que me deje escribir numeros y letras pero que no me deje escribir algun otro caracter
Respuesta:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
‘Acepta numeros y letras…
If Not Char.IsLetterOrDigit( e.KeyChar ) And e.KeyChar vbBack Then
e.Handled = True
End If
End Sub
Este codigo me da este error
El operador And no esta definido para los tipos Boolean y Char
Chicos alguna sugerencia para la consulta?? Esperamos su colaboracin.
El 09/08/11,
Hola que tal me gustaria saber como puedo ingresar solo numero pero que acepte puntos y coma
Puedes probar esto?
PrivateSub TextBox1_KeyPress(ByVal sender AsObject, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim cadena AsString cadena = «1234567890;.,» If InStr(cadena, LCase(e.KeyChar), CompareMethod.Text) = 0 Then e.KeyChar = Nothing EndIf EndSub
//Nen el evento keypress del la caja de texto q quieras validar, lo encontr en este foro mralo http://www.foro.vb-mundo.com/f25/textbox-letras-punto-y-coma-13435/
Me avisas si te funcion?
Saludos, Andy
Hola y como le hago para que me de formato de nmbre, es decir que si se ingresa en mayusculas o minusculas, automaticamente me ponga la primeraletra en mayusculas y lo siguiente en minusculas. Ejemplo:
que se ingrese asi «hola amigos»
y me arroje esto «Hola Amigos»
hola me gustaria mucho saber como puedo hacer para que el textbox solo acepte los caracteres «A», «E», «I», «V», «X» y para el caso de que «acepte solo numeros» pueda aceptarme la «X» tambien aparte de los numeros… agradeceria mucho me pudieras ayudar con este problema que tngo, saludos
excellent points altogether, you simply gained a new reader.
What might you suggest about your submit that you just made some days ago?
Any sure?
Estos Codigos son compatibles con Visual Basic 2010 ??
Yo creo que si
Saludos, Ing. Andy Santiago Gonzles del Valle, ITIL, COBIT Consultor en TI Movistar: 996-599517 – RPM: #608976 Claro (RPC): 980-530523
y como podria limitar un textbox para que solo pueda tener numeros enteros del 0 al 9 para un rut, tengo el DV separado en otro textbox y lo tengo validado, solo me falta limitar el textbox del rut para que solo puedan introducir numeros del 0 al 9, en visual basic 2010 … favor tu ayuda . gracias (:
hola una pregutna quiero saber como hago si quiero que el textbox me lea numeros y letras cuando le hago click . tengo 2 checkbox el primero es de numero y el segundo solo letras y cuando le hago click a los dos deben de dejame escribir en msi textbox letras y numero me podrias ayudar con lso codigos por favor.
MUCHAS GRACIAS ME SIRVIO
Hola como seria para q no me aceptara decimales?
Como hago par que me deje entrar sólo numeros más la letra K en c#
hola, como puedo hacerle para que mi textbox4 acepte espacio entre cada nombre???, es decir «JUAN MANUEL», por que con la validación que coloque me limita solo al primer nombre, :
Private Sub TextBox4_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
‘VALIDACION PARA QUE SOLO SEAN LETRAS
If Char.IsLetter(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
gracias
hola, como puedo hacerle para que mi textbox4 acepte espacio entre cada nombre???, es decir “JUAN MANUEL”, por que con la validación que coloque me limita solo al primer nombre, :
Private Sub TextBox4_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
‘VALIDACION PARA QUE SOLO SEAN LETRAS
If Char.IsLetter(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
gracias
Hola para que deje solo letras y espacio unicamente hay que agregar el Char.IsSeparator(e.KeyChar) que lee si es la barra de espacio el codigo quedaria asi:
If Char.IsLetter(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsSeparator(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
espero les sirva, saludos y bendiciones.
Tengo una pregunta.. Estoy haciendo un programa en el cual deseo crear una busqueda pero la busqueda se basa en un textbox y una area determinada la cual el usuario lo decidira dependiendo de su busqueda.. Como hago para que el textbox funcione en busqueda con el area determinada la cual esta en un comboBox.. Ayuda??
Hola
Este código funciona igual en visual studio 2010 y 2012??
hola y como puedo hacer para que este código me mande un mensaje de error al escribir una letra en el texbox de números y así mismo si escribo un numero en el texbox de letras.
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub textbox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If Char.IsLetter(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
If e.Handled = False Then
End If
End Sub
End Class
muy bueno me sirvio de mucho esta genial
Increíble. Le adicioné un par de modificaciones para que además me verifique (Dentro de la función que valida números) que se use el punto como símbolo decimal y que además no se repita.
Muchas gracias.
una consulta se puede hacer para que acepta solo numero y solo 1 letra en especifico ejemplo 123456789k
Hola buen dia! Para que puedsas hacer que un textbox solo acepte letras y espacios! Ejemplo; “José Manuel” ah por cierto que ecepte acentos.
Actualmente tengo lo siguiente:
Private Sub txtNombres_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNombres.TextChanged
txtNombres.Text = StrConv(txtNombres.Text, vbProperCase) ‘ convierte la primera letra a mayuscula
txtNombres.SelectionStart = Len(txtNombres.Text)
txtNombres.Text = LTrim(Replace(txtNombres.Text, » «, » «)) ‘no acepta espacios en blanco al inicio y solo un espacio entre palabras
txtNombres.SelectionStart = Len(txtNombres.Text)
End Sub
Gabriela Zapata pasame tu mail
PUEDEN ENVIARME ESTA VALIDACION PERO PARA JAVA ECLIPSE VALIDANDO EL TEXTBOX
Muy buen aporte, por fin un colaborador que es practico y sencillo.
muchas gracias 🙂
Porque se me cancela automaticamente el visual basic para mi laptop con windows 6
Perdon con windows 10
Gracias muy util
Yоu’re so cool! I do not think I’ve truly read a single thing like that before.
So nice to find somebody with some genuine thoughts on this topic.
Seriously.. many thanks for starting this up. Thіs web site is somᥱthing that is required on the
web, someone with a little originality!
If you wish for to take a great deal from tthis paragraph then you have
to apply such techniques to your won weblog.
Private Sub TextBox6_KeyPress(ByVal CajaTexto As System.Windows.Forms.TextBox, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
ElseIf e.KeyChar = «.» And Not CajaTexto.Text.IndexOf(«.») Then
e.Handled = True
ElseIf e.KeyChar = «.» Then
e.Handled = False
Else
e.Handled = True
End If
TextBox8.Text = Val(TextBox8.Text).ToString(«###.#.###»)
If TextBox4.Text = «0» And TextBox5.Text = «0» And TextBox6.Text = «0» Or TextBox7.Text = «0» Or RadioButton1.Enabled = False And RadioButton2.Enabled = False And RadioButton3.Enabled = False Then
MessageBox.Show(«No se puede realizar la operación. Faltan datos o no ha seleccionado alguna operación», «Falló operación», MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Estaba buscando esa informacion hace duración, te lo agradezco, estoy
de pacto con tu punto de vista y forraje igual.
Despues de buscar mucho por Internet encontre lo
que buscaba. Genial!!! muchas gracias
I think everything said was very logical. However, consider this, suppose you were to
write a awesome headline? I ain’t saying your content is not solid, however
what if you added a post title that grabbed folk’s attention? I mean Solo aceptar números
o solo letras en un TextBox – VB.Net 2005 | Relaciones Informáticas is kinda boring.
You might peek at Yahoo’s home page and watch how they create news titles to get viewers to open the links.
You might add a video or a related picture or two
to get people interested about everything’ve got to
say. Just my opinion, it could make your website
a little livelier.
כבר מעל לעשור רנקום קריאייטיב נחשבת לחברה מובילה בעולם
הפרסום הדיגיטלי.
נוסדנו בשנת 2003, החברה היחידה המספקת את כל שירותי המדיה והאינטרנט במקום אחד:
בניית אתרים ופיתוח אפליקציות, קידום אתרים, שיווק ופרסום, עיצוב גרפי ופתרונות מחשוב.
צוות החברה הינו בעל רזומה עשיר
ומקצועי. הצוות כולל מעצבים ואנשי ארט, מפתחים, טכנאים, אנשי שיווק ומומחים של קידום
אתרים מקצועי שעובד.
צוות זה עובד בסינרגיה מושלמת במטרה אחת: לבנות
ולתחזק ללקוחותינו את כל מערך הפרסום הדיגיטלי,
לבדל אותו ממתחריו, ולייצר לו ערך מתמשך והחזר השקעה מקסימלי.
חברה לבניית אתרים, בניית
אתרים בחיפה, בניית אתרים בקריות, מעצב גרפי בחיפה, מעצב גרפי בקריות, עיצוב גרפי בחיפה, עיצוב גרפי
בקריות
Everything is very open with a really clear clarikfication of the challenges.
It was really informative.
Your site is very useful. Thanks for sharing!
I got this site from my buddy who shared with me on the topic of this site and
now this time I am browsing this site and reading very informative articles at this place.
Hi to every one, as I am truly keen of reading this weblog’s post
to be updated daily. It carries pleasant information.
Muchas gracias por el aporte
As the admin of this website is working, no doubt very shortly it will be renowned, due to its feature contents.
I am sure this write-up has touched all the internet viewers, its
really really pleasant post on building up new website.
Quality posts is the key to concentrate the visitolrs to pay a quick visit
the page, that’s what thks website is providing.
Hi I am so happy I found your web site, I really found
you by error, while I was looking on Bing for something else,
Regardless I am here now and would just like to say many thanks for a incredible post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read through it all at the
minute but I have bookmarked it and also included your RSS feeds, so when I have time I
will be back to read a lot more, Please do keep up the superb job.
COMO HACER QUE MI TEXTBOX ACEPTE SOLO NUMEROS
If you are going for finest contents like myself,
simply pay a quick visit this web page daily as it provides quality contents,
thanks
Wonderful beat ! I woulⅾ choose tо apprentice ѡhile y᧐u amend
your web site, hoow copuld і subscribe foor a blog
website? Тhe account aidesd me a acceptable deal. І haⅾ beеn tiny Ƅit acquainted of this
yօur bdoadcast pгovided bright ϲlear concept
Simply want to say your article is as amazing.
The clarity on your put up is simply cool and i could suppose you are knowledgeable in this
subject. Well together with your permission allow me to grab
your feed to keep updated with coming near near post.
Thank you a million and please keep up the enjoyable work.
La fissure anale peut être observée en cette occasion.
Vi este video y me funcionó a las mil maravillas, en la descripción comparten el código: https://www.youtube.com/watch?v=ATDyPCUVtHU
Buen día
Necesitaría resolver lo siguiente…
Si con este código:
«If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If»
… solo imprimo números; cómo puedo (en la misma rutina), excluir un solo número.!??
Digo solo imprimo o ingreso del 1 al 9 pero que no permita ingresar el 5, por ejemplo.
Sé que hay que hacerlos antes del «e.Handled = True». Prove varias formas y no encuentro como resolverlo. Si alguien puede darme una mano lo agradecería.
Un saludos cordial.
Visual basic 2014 se puede ?