By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,972 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,972 IT Pros & Developers. It's quick & easy.

Restrict user to enter numeric value in textbox

P: 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
Share this Question
Share on Google+
5 Replies


P: 5
have u used any of the validators?
Nov 10 '06 #2

100+
P: 366
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

P: 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
100+
P: 107
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
100+
P: 217
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.