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

How do i restrict entering non-numeric data

sp
Hello Everybody,

How can I restrict the user entering non-numeric data in textbox control
on server side using asp.net. Any Code sample or suggestions are appreciated.

Thanks in advance
sp
Nov 18 '05 #1
2 1694
Hey.

Server side:

protected TextBox txt;
protected Label lbl;

private void Page_Load(object sender,System.EventArgs e)
{
try
{
IsPostBack ? lbl.Visible = false : Verify();
}
catch(TextBoxIsNotValid)
{
lbl.Visible = true;
lbl.Text = "Whatever message";
}
}
private void Verify()
{
try
{
int.Parse(txt.Text.Trim());
}
catch
{
throw new TextBoxIsNotValid();
}
}

Separate class somewhere:

public class TextBoxIsNotValid : System.Exception
{
public TextBoxIsNotValid() : base("Some message to log if needed.");
}

Hope it'll help.
Kikoz

"sp" <sp@discussions.microsoft.com> wrote in message
news:26**********************************@microsof t.com...
Hello Everybody,

How can I restrict the user entering non-numeric data in textbox control
on server side using asp.net. Any Code sample or suggestions are
appreciated.

Thanks in advance
sp

Nov 18 '05 #2
With JavaScript, you can capture keystrokes, if you wish to go that far. On
the server side, you can validate and refuse bad data. It is your choice how
heavy you want your front end to be.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"sp" wrote:
Hello Everybody,

How can I restrict the user entering non-numeric data in textbox control
on server side using asp.net. Any Code sample or suggestions are appreciated.

Thanks in advance
sp

Nov 18 '05 #3

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

Similar topics

3
by: vijay21 | last post by:
hi all, Can we restrict the number of characters that the user can input in a javascript prompt? my browser hangs whenever i try to input more than 2048 characters in it. Thanks for any help
28
by: gc | last post by:
Hi, What is the purpose of the restrict keyword? gc
10
by: sconeek | last post by:
hi all, i have a textfield where i would like the user to input only Y or N. can somebody tell me how can i restrict the user from entering any other character, number or special character....
2
by: Tarkeshwar | last post by:
Hi All, I want to restrict the user from being entering the value in <input type="file">. It works fine in IE but not in Mozilla. I am sending my code also which works in IE and not in Mozilla.Can...
2
by: den 2005 | last post by:
Hi everybody, How do restrict entering these characters <>\"%';()& and telling user these caharcters are not allowed to be enter in the textbox field using RegularExpression Validator? I put in...
3
by: divaof_7 | last post by:
I've a textbox field, where user enters his name. I want to restrict him from entering double and singls inverted commas.What kind of function should i write.
1
by: =?Utf-8?B?Qw==?= | last post by:
I want to restrict the user entering nonalphanumeric keys using Javascript onKeypress. One exception is that I want to allow the user to enter spaces. How can I do this? Thanks in Advance.
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
6
by: rainy6144 | last post by:
Does the following code have defined behavior? double *new_array(unsigned n) { double *p = malloc(n * sizeof(double)); unsigned i; for (i = 0; i < n; i++) p = 0.0; return p; }
0
by: copx | last post by:
Restrict keyword questions How far does the guarantee that an object is not accessed through another pointer go? I mean, all examples I have seen are simple stuff like: int f (int *restrict x,...
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: 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
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
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
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.