473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

only numbers

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

Thanks
Aug 17 '06 #1
3 1615
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********@hotm ail.com
http://www.nathansokalski.com/

"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:CE******** *************** ***********@mic rosoft.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 RegularExpressi onValidator 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***@discussi ons.microsoft.c omskrev i melding
news:CE******** *************** ***********@mic rosoft.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
10419
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 into a textbox. thankz in advanced -Ro -------------------------------------------------------------------- " Reality is an illusion caused by...
1
2139
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 details what i'm looking for. I'm sure its just a small detail. But I'm in the dark. // numbers1to10only.cpp #include <iostream.h>
14
3417
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 long. I am writing a program in Visual C++ 6 SP5. My code has a lot of "if" statements - 19 to be exact. If the if statements are true (technically,...
2
13684
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 18:39:24 +0200 Local: Fri,Jul 15 2005 12:39 pm Subject: Re: Summer 2005 browsers' test set ?
2
1733
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 numbers that match that particular test#. One test# can have multiple OOS#s, but its must be that, Test#=OOSNumber. I have the following code so far:...
38
2140
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. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
3
3465
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 following script does that OK. However, I want also to make sure that only "numbers" are entered and no other characters. Again the attached does...
4
21015
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 else if yes then remove the spaces
2
7929
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 characters: If txtname.Text = "" Then MsgBox "enter the name", vbOKOnly, "PAYROLL"
2
2214
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 (envno.Text) <= neg Or Then MsgBox("Please enter Positive numbers only.", vbInformation) envno.Text = "" ...
0
7527
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...
0
7967
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...
0
7819
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...
0
6052
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...
1
5377
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...
0
5097
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...
0
3505
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1953
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 we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.