470,596 Members | 1,356 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

Restrict user to enter numeric value in textbox

2
hi all
i would like to know how to restrict user from entering numeric value
ina textbox..using C#
if user try to enter text it shouldnt be allowed..
i tried errror provider..
but it doesnt met my requirement..
thanks in advance for ur valuable reply
let me know the best to do it

urs
SKS
Nov 10 '06 #1
5 12905
have u used any of the validators?
Nov 10 '06 #2
nmsreddi
366 256MB
hello

if you are familar with java script then its better choice to use (web application)

other wise you have write the code in codebehing using C# by using ASCII values verify the each key stroke value if the mach is success then do nothing

if the condition fails have a popup(if windows pplication)


try it out


regards

nmsreddi
Nov 13 '06 #3
Attiq
1
H!
To restrict user from different inputs you can use these fuctions:
IsDigit
IsHighSurrogate
IsLetter
IsLetterOrDigit
IsLower
IsLowSurrogate
IsNumber
IsPunctuation
IsSeparator
IsSurrogate
IsSurrogatePair
IsSymbol
IsUpper
IsWhiteSpace


private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsDigit(e.KeyChar) )
{ MessageBox.Show("Bad Input");
e.Handled = true; ;
}
}
Mar 11 '08 #4
VijaySofist
107 100+
hi all
i would like to know how to restrict user from entering numeric value
ina textbox..using C#
if user try to enter text it shouldnt be allowed..
i tried errror provider..
but it doesnt met my requirement..
thanks in advance for ur valuable reply
let me know the best to do it

urs
SKS
Add the following code in the script side of your html text box control

Expand|Select|Wrap|Line Numbers
  1. onkeydown="if (window.event.keyCode > 47 && window.event.keyCode < 58){ return false; }"
All The Best
With Regards
Vijay. R
Apr 11 '08 #5
malav123
217 100+
Hi,
just write the following function in javascript for your requirement...
Expand|Select|Wrap|Line Numbers
  1. function noNumeric()
  2. {
  3.        if( !isNaN(yourtextbox.value))
  4.         {
  5.                    alert("Numerics not allowed");
  6.                    return false;
  7.           }
  8. }
  9.  
Apr 11 '08 #6

Post your reply

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

Similar topics

3 posts views Thread by divaof_7 | last post: by
2 posts views Thread by colleen1980 | last post: by
1 post views Thread by =?Utf-8?B?Qw==?= | last post: by
2 posts views Thread by jd | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.