473,769 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET input data validation from a Text Box

I am new to VB.NET and have a question on validating user input from a
Text Box. I'm writing a small program where I want to check the users
input data and determine if it's an Integer or a Decimal. I guess I
want to go one step further than just checking for IsNumeric. I have
searched this Work Groups' database and did not find exactly what I
need. I have tried GetType, VarType, and the Val Function using the
Text Box data, without success. I did find, however, that I could
assign the data directly to a variable and the above work fine, so it
must be how I am trying to get the data from the Text Box.

Since the Text Box information is Text, I assume I need to convert it
to numeric before checking it. But, All I've found is conversions to
specific types (Integer, Double, etc), and not into just numeric.
That doesn't seem to help me with what I'm trying to do. What am I
missing?

This is the code I'm using to try to make this validation:

Dim TestData

TestData = TBoxInput.Text

‘What needs to go here??

If VarType(TestDat a) = VariantType.Int eger Then
TBoxResult.Text = "It's an Integer"
End If

I assume there must be a simple solution to this problem, but I just
haven't found it. Any help would be greatly appreciated.

Jim B
Nov 20 '05 #1
2 42891
Try this:

If instr(1,Textbox 1.Text,".") = 0 then
TextBox1.Text = "It's an Integer"
Else
TextBox1.Text = "It's a Decimal"
End If

"Jim B" <jh*****@netsca pe.net> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
I am new to VB.NET and have a question on validating user input from a
Text Box. I'm writing a small program where I want to check the users
input data and determine if it's an Integer or a Decimal. I guess I
want to go one step further than just checking for IsNumeric. I have
searched this Work Groups' database and did not find exactly what I
need. I have tried GetType, VarType, and the Val Function using the
Text Box data, without success. I did find, however, that I could
assign the data directly to a variable and the above work fine, so it
must be how I am trying to get the data from the Text Box.

Since the Text Box information is Text, I assume I need to convert it
to numeric before checking it. But, All I've found is conversions to
specific types (Integer, Double, etc), and not into just numeric.
That doesn't seem to help me with what I'm trying to do. What am I
missing?

This is the code I'm using to try to make this validation:

Dim TestData

TestData = TBoxInput.Text

'What needs to go here??

If VarType(TestDat a) = VariantType.Int eger Then
TBoxResult.Text = "It's an Integer"
End If

I assume there must be a simple solution to this problem, but I just
haven't found it. Any help would be greatly appreciated.

Jim B

Nov 20 '05 #2
Try using the Validating event for the text box.
Gary

"Jim B" <jh*****@netsca pe.net> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
I am new to VB.NET and have a question on validating user input from a
Text Box. I'm writing a small program where I want to check the users
input data and determine if it's an Integer or a Decimal. I guess I
want to go one step further than just checking for IsNumeric. I have
searched this Work Groups' database and did not find exactly what I
need. I have tried GetType, VarType, and the Val Function using the
Text Box data, without success. I did find, however, that I could
assign the data directly to a variable and the above work fine, so it
must be how I am trying to get the data from the Text Box.

Since the Text Box information is Text, I assume I need to convert it
to numeric before checking it. But, All I've found is conversions to
specific types (Integer, Double, etc), and not into just numeric.
That doesn't seem to help me with what I'm trying to do. What am I
missing?

This is the code I'm using to try to make this validation:

Dim TestData

TestData = TBoxInput.Text

'What needs to go here??

If VarType(TestDat a) = VariantType.Int eger Then
TBoxResult.Text = "It's an Integer"
End If

I assume there must be a simple solution to this problem, but I just
haven't found it. Any help would be greatly appreciated.

Jim B

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2175
by: Gleep | last post by:
Hi PHP coders, I've got an issue I'm stuck with. Imagine there is a large form that has 5 columns and 20 rows. In each row there is a check box - then 4 input fields. I already have the code that inserts all the data BUT the validation is a nightmare. What I need is. If an entire row is empty (not checked or filled out) that's OK. However if a user fills in one or two input fields within a row - that's NOT ok. The entire row needs...
0
4236
by: lucas | last post by:
Hi, I have a simple input form that i use to add records to a sql server database. Bellow that is a datagrid that has one template column that I use to dispaly the 3 fields with some html formating. the datagrid also has paging. I'm doing a ASP.NET guestbook. I know some things could be improved like adding some error handling and caching the dataset instead of querying the database on every page load....but I'm still working on the...
1
1525
by: Paul | last post by:
Hi, I'm developing a search facility for my web app. In order for the search criteria to be valid the user must (a) enter some text in a text box and check and least one checkbox (of which there are two) and/or (b) select at least one item from a multiple select list box. I've written the javascript to do the client side validation which gets called on the click event of my search button. I'd like to implement server side validation...
2
1268
by: headware | last post by:
I realize that when making a web application, performing input validation in the browser is good because it prevents postbacks. However, input checking that goes beyond making sure a value exists or that it's not alphabetic when it's supposed to be numeric is arguably best left to the business tier code on the server where there is access to other data. My questions, is what's the best way to communicate complicated error checking...
6
4136
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page comes back with all the data intact, except for the upload object. The text box for "MyFile" (my example) is always cleared. Why is that and is there a way to stop that from happening? Thanks,
2
2918
by: Chad | last post by:
I have a textbox control, txtMeasurement, that I want to allow only numeric decimal input. I thought to use a client side validation control to ensure that the data entered is of type "Double". 'Measurement Validation (Range Validator) Dim MeasurementRangeValidator As New RangeValidator 'validate that the measure is numeric MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID| MeasurementRangeValidator.Display =...
5
2570
nathj
by: nathj | last post by:
Hi, I have been looking around the forum and the web for a way to achieve this and so far I have drawn a blank. So I head to the forum as I'm sure someone knows how to do this. I have a form which I validate as the user enters data, this is straight forward enough. Part of the validation ensures that all mandatory fields are entered before the continue button is enabled. (unfortunately this is a development site at present and so I can't...
1
4006
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. Depends on the pull down list selection, I use script.aculo.us to validate the user input before submit and pass the necessary data, such as contact type, contact information and ranking to a php program for updating. This form should allow multiple...
18
2409
vikas251074
by: vikas251074 | last post by:
I am using ASP In my company, all employees have to sent materials out of premises. Any employee who need to sent material out will use this web application. In the first page, an employee enters firm name, vehicle no, driver name, purpose, persons taking out, received by, remarks. In the second page, employee enters no. of materials to be taken out. In the third page, displays no. of rows for entry of material details like material name,...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.