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

Input value integer alone

Hi all , How can we restrict user to enter integer alone in textbox (like using ascii code restriction in keypress event in VB).

since keypress event not available for textbox property in asp.net 1.1 how can we overcome this problem
Feb 19 '07 #1
3 1869
Frinavale
9,735 Expert Mod 8TB
Hi all , How can we restrict user to enter integer alone in textbox (like using ascii code restriction in keypress event in VB).

since keypress event not available for textbox property in asp.net 1.1 how can we overcome this problem
I'm sure there is some JavaScript out there that will do this for you. I know that there is an extender that comes with the ASP.NET AJAX package that filters text boxes for you and will not accept user input that isn't a number... but to use you will require .NET Framework 2 or higher to run it...and of course download ASP.NET Ajax.

If you are restricted to only using VB, I'd suggest letting the user enter whatever they would like to and then displaying an error message stating that they are only allowed to enter numbers as a valid input value.

You could also use a RegularExpressionValidator that checks to see if numbers have been entered into the Textbox. This will not prevent the user from entering other values in the textbox but will catch the error before it is submitted to the server

Remember that the RegularExpressionValidator (as well as the other validation tools that come with Visual Studio) use JavaScript to do the checking for you.

Hope this helps

-Frinny
Feb 19 '07 #2
dotneto
36
I'm sure there is some JavaScript out there that will do this for you. I know that there is an extender that comes with the ASP.NET AJAX package that filters text boxes for you and will not accept user input that isn't a number... but to use you will require .NET Framework 2 or higher to run it...and of course download ASP.NET Ajax.

If you are restricted to only using VB, I'd suggest letting the user enter whatever they would like to and then displaying an error message stating that they are only allowed to enter numbers as a valid input value.

You could also use a RegularExpressionValidator that checks to see if numbers have been entered into the Textbox. This will not prevent the user from entering other values in the textbox but will catch the error before it is submitted to the server

Remember that the RegularExpressionValidator (as well as the other validation tools that come with Visual Studio) use JavaScript to do the checking for you.

Hope this helps

-Frinny
Hi, I think the best way is to use regular expression validator, something like \d* will do it i guess.
Feb 19 '07 #3
Frinavale
9,735 Expert Mod 8TB
Hi, I think the best way is to use regular expression validator, something like \d* will do it i guess.

Just remember that there are ways around this validator because its javascript. You should do a server side check as well if you want to be sure your user input is correct...its not hard to do a Integer.Parse(input) in a try catch.

Happy Coding
:)
-Frinny
Feb 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: nkp | last post by:
Sorry guys, basic questions..... 1)how do you prevent negative numeric input in a text box (-2345 etc) 2)how do detect /prevent input of LESS than 8 characters in a text box( where a password must...
6
by: a | last post by:
(I've reached that familiar place where I've got a nagging little problem in a program I'm writing but I've been staring at code for too long and I probably wouldn't be able to recognize the answer...
5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
13
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
0
by: stevenhaochen | last post by:
I add a user control (a simple textbox control) to customize datagridview column to test how to add user control to datagridview. I found a weired behavior. I can not input "q", "!", "#". But I...
5
by: Kavya | last post by:
I saw these two ways for validating input First Way -------------- #include <iostream> #include <limits> using namespace std; int main() {
9
by: seep | last post by:
hi i m finding following error on the code that i wants to use to get all record from table via store procedure with paging. the error is : Input string was not in a correct...
14
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num;...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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...

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.