473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how do I set a Textbox to only accept numerical values in vb .net

how do I set a Textbox to only accept numerical values in vb .net
Mar 10 '08 #1
3 2009
how do I set a Textbox to only accept numerical values in vb .net
You can do this with keyUp event handler and SuppressKeyPress property of KeyEventArg like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
  2.         If e.KeyValue < 48 Or e.KeyValue > 57 Then
  3.             e.SuppressKeyPress = True
  4.         End If
  5.     End Sub
Mar 10 '08 #2
If you are using .NET 2.0, try using the MaskedTextBox control.

MaskedTextBox
Mar 10 '08 #3
Hi there,

If you wanna apply server side validation for not allowing anything else then numbers use the acii code present in second solution but it is advised to use client side validation ie in your vb.net toolbar, use regular expression validator..for that validator in the properties window enter a regular expression.

Hope this help..

Regards
Mar 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: rodger | last post by:
Hi all, how do I set a Textbox to only accept numerical values in vb .net many thanks rodger
2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
1
by: dln | last post by:
Howdy. I'm a bit new to C# and got a couple of quick questions that perhaps someone can help me answer. First, is there a property that you set on a TextBox control that will force the control to...
2
by: Abra | last post by:
Hi, I would like to allow only some pre-defined characters to be typed in a TextBox (for example only integer numerical, or float numerical, or only a set of letters and so on). How can this be...
2
by: colleen1980 | last post by:
There is a textbox and a drop down. Once user enters any value in the textbox he has to select the option from drop down otherwise the cursor will not allow to move anywhere else accept the drop...
7
by: weg22 | last post by:
Hi all, I need to impose maximum and minimum numerical limits on a textbox. I'd prefer not to code these in (since I have many textboxes and the limits on each are different) and was wondering...
1
by: mokete | last post by:
HI I have textbox that accept only numeric values,but I need it to accept only Currency. My code in vb6 is if isnumeric(Textbox) =false then ' this will not accept if not numeric value...
2
by: nussu | last post by:
Hi, A textbox has to accept only numeric values by using validation controls in .net 2.0 Plz help me ... Regards, Nussu
2
by: cephal0n | last post by:
I have this peroblem thats really bugging me for days, please have a patience to read it and help me find the probplem because I knew I missed it and just cant tell where. I have a table named...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.