473,513 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Number only input

Is there a simple way of only allowing numeric inputs into a textbox?

Thanks
Nov 21 '05 #1
4 1636
you may use one of two ways:

1) when any character except numbers in entered give a TRUE value to
e.Handled,so the event will ignore the character,and that is by comparing the
ASCII of the character with numbers ASCII.

2)but a try catch blocks and parse the textbox text to integer in try block
,so it will go to the catch block when there is charactres other than numbers
entered, now in the catch block you should empty the text property in the
textbox, the result will be emptying the textbox when non-numbers characters
are entered.

"Nick S" wrote:
Is there a simple way of only allowing numeric inputs into a textbox?

Thanks

Nov 21 '05 #2
Hello,
Use client-side JS validation. Here is a sample:
http://www.mredkj.com/tutorials/validate2.html

"Nick S" <Ni**@NoSpam.NTWorks.fsnet.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a simple way of only allowing numeric inputs into a textbox?

Thanks

Nov 21 '05 #3
You could use some Javascript like this:

<script language="Javascript">
function ValidateNumeric()
{
var keyCode = window.event.keyCode;
if (keyCode > 57 || keyCode < 48)
window.event.returnValue = false;
}
</script>

Or if you want to get fancier you can inherit and extend the TextBox control
with such functionality, as in this example:
http://SteveOrr.net/articles/InheritAndExtend.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Nick S" <Ni**@NoSpam.NTWorks.fsnet.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a simple way of only allowing numeric inputs into a textbox?

Thanks

Nov 21 '05 #4
You can also use Regular expressions
Patrick
**Lots of choices for you buddy..:)
"Nick S" <Ni**@NoSpam.NTWorks.fsnet.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a simple way of only allowing numeric inputs into a textbox?

Thanks

Nov 24 '05 #5

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

Similar topics

8
12013
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between...
33
25617
by: Steven Bethard | last post by:
Is there a good way to determine if an object is a numeric type? Generally, I avoid type-checks in favor of try/except blocks, but I'm not sure what to do in this case: def f(i): ... if x < i:...
9
16987
by: fooboo | last post by:
Does anyone know if a easier way (built in function, or something) that can verify that a string is an alphanumeric number? Here is what I am doing now: for(i=0; i < strlen(temp); i++){...
5
6818
by: glegipon | last post by:
As Tom Cahill would require, my challenge is (according to the "three R's") Reproducible: if run on OS 9.x, the monthly payment does not show up in the text box: Recognizable: I believe the...
4
1751
by: c676228 | last post by:
Hi everyone, I need to write a insruance program which needs to collect multiple people information, The information for each person includes name, email, address, phone, dob etc. The DOB data...
43
6518
by: Xancatal | last post by:
Hey everybody. I need help on this one. I need to verify that a number entered by a user is not either a negative number (-100.00), or an alphabet (a, b, c, X, Y) as well as other number other than...
7
3204
by: Greatness | last post by:
Ceramic Floor Tile You’re working for a company that lays ceramic floor tile, and they need a program that estimates the number of boxes of tile for a job. A job is estimated by taking the...
19
107862
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
10
4343
by: strife | last post by:
Hi, This is a homework question. I will try to keep it minimal so not to have anyone do it for me. I am really just stuck on one small spot. I have to figure out the highest number from a users...
5
8562
by: kaushal30 | last post by:
I am getting this error when I call a stored procedure from my C# code. It is a simple stored procedure with six params that inserts data : PROCEDURE LHD_SUR_ADMNEXP_HDR_INS ( ...
0
7257
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,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
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
7535
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
7521
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...
1
5084
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...
0
1591
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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.