470,624 Members | 2,393 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to validate textbox accept only negative float numbers in .net

Hi,

Iam developing windows application using vb.net with c#.net.In this i want to validate textbox accept only negative float numbers like -2.3 etc....
please help me.
Aug 20 '08 #1
6 5117
r035198x
13,262 8TB
What have you tried so far?
Aug 20 '08 #2
madankarmukta
308 256MB
HI,
You can use regular expression for this.. This is very effective to validate the any input from the user.

Thanks!
Aug 20 '08 #3
cloud255
427 Expert 256MB
A try catch statement trying to parse the input to a float will allow you to check if the number is a float. Then just multiply by -1 and see if the result is less than 0.
Aug 20 '08 #4
jodi
5
is this a windows app?

if it is, then you need to do something like this in the OnTextChanged event:

decimal dec;

decimal.TryParse(this.Text, out dec);

if (dec < 0)
Ok
else
whatever

if you want to put a mask on your textbox, you can try several there are in the net to be downloaded

tried google and the first seems to do what you want
http://www.csharphelp.com/archives2/archive305.html

cya
Aug 20 '08 #5
Plater
7,872 Expert 4TB
It would probably be overkill, but there is a MaskedTextBox class in .NET for windows applications that could be used.
Aug 20 '08 #6
Curtis Rutland
3,256 Expert 2GB
How do you develop an app using "vb.net with C#.net"?
Aug 20 '08 #7

Post your reply

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

Similar topics

6 posts views Thread by Nobody | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.