473,387 Members | 1,435 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,387 software developers and data experts.

how to get the type of a textbox

Hi,

how can I get the type of what was entered into a textbox?
I want to validate the user inputs, so I would like to know
if what the user entered was a number or not.

thanks,

Stefan
Jul 21 '05 #1
5 1061
On the KeyDown event trap e.KeyChar
"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
Hi,

how can I get the type of what was entered into a textbox?
I want to validate the user inputs, so I would like to know
if what the user entered was a number or not.

thanks,

Stefan

Jul 21 '05 #2
Okay,

so I really have to do that all by myself,
character for character??
???

Isn't there some function that automatically does it?

Thanks,

Stefan
Jul 21 '05 #3
In a web form, there are validation controls that do the job for you.

If not, you have to check the text yourself.
"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
Okay,

so I really have to do that all by myself,
character for character??
???

Isn't there some function that automatically does it?

Thanks,

Stefan

Jul 21 '05 #4
It's really simple, keypress only passes one character at a time, so you can
just check the current key. If it's a number for isntance, ignore it.

like Scott mentioned, if you are using ASP.NET you can use the Regex
validators. Similarly, you can easily build this in on the desktop
controls.
"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
Okay,

so I really have to do that all by myself,
character for character??
???

Isn't there some function that automatically does it?

Thanks,

Stefan

Jul 21 '05 #5
You can do this with regular expressions as mentioned in other replies to
your post.
Or you can create a function, say StringToInt("42");

Here's some code which does pretty much what StringToInt() might do

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
string s = textBox1.Text;

int num = IsNumber(s);
}

private bool IsNumber (string astr)
{
try {
int i = Convert.ToInt32(astr);
return (true);
}
catch (System.Exception) {
return (false);
}
}

maybe something like that?

hth,
J

"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
Okay,

so I really have to do that all by myself,
character for character??
???

Isn't there some function that automatically does it?

Thanks,

Stefan

Jul 21 '05 #6

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

Similar topics

4
by: j.t.w | last post by:
Hi All. I'm having a problem with my Date of Birth textbox. When I open the ..htm file, the "DoB" textbox is flat with a border. All of my other textboxes are sunken and are yellow. When I...
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...
0
by: Jim Heavey | last post by:
I am using the DataList The ItemTemplate has a button and a label. The label field is bound to a datatable and a field called "Narrative". The button is labeled "Edit". When the edit button is...
1
by: questions | last post by:
Can anyone offer any advice or point me in a direction of help. I would like to be able to load a give webcontrol, say a TextBox from it's type (which would be stored in either XML or SQL). ...
5
by: J L | last post by:
I am trying to step through the controls on a form and take some action when I find a specific type. I dont know how to express this in an If or Select clause. I tried: Dim Ctrl As Control...
12
by: Joel Byrd | last post by:
I'm having a little problem with using type-ahead functionality for an auto-suggest box. Sometimes, when I start to type something and the type-ahead shows up, the AJAX will send a request query...
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
0
by: Sam | last post by:
Folks.. I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data...
0
by: DC | last post by:
Why would this code give me the error "Could not load type System.Web.UI.WebControls.AccessDataSource from assembly System.Web, Version=1.0.5000.0" at line 16... <form id="form1"...
9
by: Alexander Widera | last post by:
hi, is it possible to return an object of an unknown (but not really unknown) type with an method? i have the following situation: - a variable (A) of the type "object" which contains the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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...

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.