Number only input

G

Guest

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.
 
S

Steve C. Orr [MVP, MCSD]

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
 
P

Patrick.O.Ige

You can also use Regular expressions
Patrick
**Lots of choices for you buddy..:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top