473,324 Members | 2,124 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,324 software developers and data experts.

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(TestData) = VariantType.Integer 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 42864
Try this:

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

"Jim B" <jh*****@netscape.net> wrote in message
news:6a**************************@posting.google.c om...
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(TestData) = VariantType.Integer 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*****@netscape.net> wrote in message
news:6a**************************@posting.google.c om...
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(TestData) = VariantType.Integer 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
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...
0
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...
1
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...
2
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...
6
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...
2
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". ...
5
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...
1
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. ...
18
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.