473,485 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

only numbers

Hi,
How can I only accept numbers in a textbox?

Thanks
Aug 17 '06 #1
3 1611
I'm not sure there is a way to do that using ASP.NET alone, but you can do
it reasonably easily using JavaScript's onkeypress event. I have written a
simple function that allows you to have TextBox Controls accept only certain
characters or sets of characters (such as uppercase, lowercase, numbers,
hexadecimal, etc.) to make it easier to do what you are trying to do. If you
would like me to send you the code for this function (it is written using
VB.NET), let me know (I don't like sending attachmements without people
asking for them). Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
Hi,
How can I only accept numbers in a textbox?

Thanks

Aug 17 '06 #2
you can do this using javascript. On KeyPress event of the textbox, check for
it's keycode and return true/false appropriately.

http://www.codingforums.com/archive/...hp?t-4568.html

Regards,
Augustin

"Chris" wrote:
Hi,
How can I only accept numbers in a textbox?

Thanks
Aug 17 '06 #3
You can use the RegularExpressionValidator to just accept digits. Look at
this for example http://aspnet101.com/aspnet101/tutorials.aspx?id=11. It's a
bit cleaner than the JavaScript keyup/keydown solution. However you get a
different result as the default validator usually fires on a different event
(like the submit of a form for example).

Richard

"Chris" <Ch***@discussions.microsoft.comskrev i melding
news:CE**********************************@microsof t.com...
Hi,
How can I only accept numbers in a textbox?

Thanks

Aug 17 '06 #4

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

Similar topics

9
10413
by: Rowan Chapman | last post by:
Hey all! I'm kinda new to VB but not to programin'. So I know what it is like when you are asked trivial questions. Could some1 please tell me what the syntax would be 2 only allow numerical data...
1
2131
by: jel | last post by:
I ran what was submitted in several forums, but it's not exactly what i'm looking for. I'm dy'n over here. Ah, the frustrations of an amateur programmer. I included the code below in c++. which...
14
3402
by: root | last post by:
Hi group, Apologies in advance if this has been asked somewhere before, but I haven't managed to get anything from the Google archives - I've been getting introductory guides to C++ all day...
2
13673
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...
2
1718
by: Sreya | last post by:
Hello..I hope someone can help me with this little that I've been having for a while. I have a form..which has many fields. one of them being a test #. what I need a combo box with only certain...
38
2130
by: Maarten | last post by:
hi all, how can i retrieve the type if a value inserted in an inputbox. what i want to do is make shure people only insert an integer type, if they don't they get an error message. ...
3
3459
by: Tom | last post by:
Being a newbie to JS, I would appreciate some advice. When a visitor enters a number into a textbox, I want to check that it is 15 digits long and then display a message accordingly and the...
4
21010
by: sreemati | last post by:
Hi, I have seen various online resources and tuturials. I ahve written a piece of code but it does not seem to work Problem defined: If not number entered (as not mandartory) ignore ...
2
7919
by: Vbbeginner07 | last post by:
Hi all Wonder if anyone can help me out to solve this: please find the code of textbox that accepts only characters and one textbox that accepts only numbers: (vb) textbox for accepting...
2
2208
by: sdanda | last post by:
Hai My textbox accepts only positive numbers.It doesnot accept even floating points also.How to this?I wrote this code //Code Dim neg As Integer = 0 If (Not IsNumeric(envno.Text)) Or...
0
7116
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
7161
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...
1
6825
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
7275
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...
0
5418
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,...
0
3058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3063
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1376
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
247
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...

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.